I've a DataTable[having 5 columns] from db which has combined data. I need to invoke a group by on this combined table and create 2 tables...one with groupedBy rows and other having items. What would be fastest way to do this in C# code? Also, I've written code below for adding columns for these 2 tables.Is that correct?
Heres my code:
string colName = "ACCOUNT_ID";
var allRows = combinedTable.AsEnumerable();
var accountRowGroups = allRows.GroupBy(row => row[colName]);
DataTable masterDataTable = new DataTable();
DataTable childPricesDataTable = new DataTable();
// Create the columns
DataColumnCollection pdCols = combinedTable.Columns;
for (int ndx = 0; ndx < pdCols.Count; ndx++)
{
string columnName = pdCols[ndx].ColumnName;
Type type = Type.GetType(pdCols[ndx].DataType.ToString());
masterDataTable.Columns.Add(columnName, type);
childPricesDataTable.Columns.Add(columnName, type);
}