Why am I not getting .CopyToDataTable() in Linq Query()

It exists in a specific namespace are you importing it?

System.Data.DataTableExtensions.CopyToDataTable() 

Also confirm the addition of this reference

System.Data.DataSetExtensions 

Your select statement is returning a sequence of strings (IEnumerable<string> or IQueryable<string>), not a sequence of DataRows. CopyToDataTable() is only available on IEnumerable<T> where T is or derives from DataRow.

Instead of select new { ... } - which will just get you a new sequence of that type, try:

select CPhysician;

Which should return the desired sequence of CPhysician rows.

Edit If you wish to convert a non-datatable-derived T to a datatable, MSDN has a sample class that reflects out any type and performs the conversion.

http://msdn.microsoft.com/en-us/library/bb669096.aspx

Tags:

C#

Linq

Asp.Net