This following code example is borrowed from MSDN here. I am not getting query.CopyToDataTable() available in my code. (see the commented line in my following code).
You need to reference the System.Data.DataSetExtensions
assembly and use the System.Data
namespace.
This issue for me was caused by using Dotnet Core 2.0, which appears to have no way to turn an IEnumerable
back into a DataTable
after it's converted.
Just adding this for anyone that comes across this question with the same issue.
Navigating further into MSDN online brings me to this page: http://msdn.microsoft.com/en-us/library/system.data.datatableextensions.aspx
It says its in the System.Data namespace (using System.Data) and you need to reference the System.Data.DataSetExtensions.dll.
It exists in a specific namespace are you importing it?
System.Data.DataTableExtensions.CopyToDataTable()
Also confirm the addition of this reference
System.Data.DataSetExtensions
I think that's because your creating a anonymous type to hold the Field
object.
Try this:
var query = from SPhysician in dtPhysicianServer.AsEnumerable()
join CPhysician in dtPhysicianClient.AsEnumerable()
on SPhysician.Field<string>("PhysicianNumber") equals
CPhysician.Field<string>("PhysicianNumber")
select CPhysician;
DataTable FilterDt = query.CopyToDataTable();
Definition of CopyToDataTable<T>
:
public static DataTable CopyToDataTable<T>(
this IEnumerable<T> source
)
where T : DataRow
So what you select with the query must be of type IEnumerable<T>
where T
extends DataRow
Have you referenced System.Data.DataSetExtensions assembly? This extension method is defined there.