Trying to return a Linq group by query into a DataTable. Getting the error
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<System.Data.DataRow>'. An explicit conversion exists (are you missing a cast?)
The I am querying a DataTable named Vendors where the data would be as follows:
Vendor Name
654797 Lowes
897913 Home Depot
800654 Waffle House
The Vendor is stored as char(6) in the DB and name as char as well... don't ask me why, I just work here :)
DataTable VendorsDT = New DataTable();
DataColumn VenName = VendorsDT.Columns.Add("Name", typeof (string));
DataColumn VenCode = VendorsDT.Columns.Add("Vendor", typeof(string));
IEnumerable<DataRow> Vendors = from row in alertsDT.AsEnumerable()
group row by new { Name = row.Field<string>("Name"), Vendor = row.Field<string>("Vendor") } into z
select new
{
Name = z.Key.Name,
Vendor = z.Key.Vendor,
};
VendorsDT = Vendors.CopyToDataTable();