I got this code
But I got the following errors:
Error 1 Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<System.Data.DataRow>'
Error 2 'System.Collections.Generic.IEnumerable<AnonymousType#1>' does not contain a definition for 'CopyToDataTable' and the best extension method overload 'System.Data.DataTableExtensions.CopyToDataTable<T>(System.Collections.Generic.IEnumerable<T>)' has some invalid arguments
var distinctRows = (from DataRow dRow in vwBusPark.toDataTable().Rows
select new { col1 = dRow["BusinessParkID"], col2 = dRow["BusinessParkID"] }).Distinct();
dataSet.BusinessPark.Merge(distinctRows.CopyToDataTable<DataRow>(), true, System.Data.MissingSchemaAction.Ignore);
I tried this:
dataSet.BusinessPark.Merge(vwBusPark.toDataTable().Rows.Except(DataRowComparer<UC010_WizardStepBusinessParkDataSet.BusinessParkRow>.Default).CopyToDataTable(), true, System.Data.MissingSchemaAction.Ignore);
But I got this 2 errors:
Error 2 'System.Collections.Generic.IEnumerable<AnonymousType#1>' does not contain a definition for 'CopyToDataTable' and the best extension method overload 'System.Data.DataTableExtensions.CopyToDataTable<T>(System.Collections.Generic.IEnumerable<T>)' has some invalid arguments
Error 1 Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<System.Data.DataRow>'
Those aren’t DataRows, so you can’t copy them to a DataTable.
Assuming that
BusinessParkhas the same column names asvwBusPark, you don’t need the LINQ query at all; instead, you can just write