I have the following DataTable:
DataTable itemsOnSkid = new DataTable();
itemsOnSkid.Columns.Add("ItemNumber");
itemsOnSkid.Columns.Add("Qty");
And I need to aggregate this datatable by itemnumber. I'm using the following linq code:
var result = from row in itemsOnSkid.AsEnumerable()
group row by row.Field<string>("ItemNumber") into grp
select new
{
ItemNumber = grp.Key,
Qty = grp.Sum(r => r.Field<int>("Qty"))
};
Problem is that I need to replace the first datatable with this result, but I'm not able to use .CopyToDataTable()
on result.
How can I convert this result back to a datatable?