GD_GRAY
asked on
Merging Data Tables with common Key ID
I have two data tables, one with say 200 rows of today's order info and another table with 5000+ rows of company info. Each table has a column named "CompanyID". What I need to do is merge or build a new table with the Company Info onto the same row as the Order with the same "CompanyID". Can anyone help with this ? I found this code but it is not working.
void MergeColumns(DataTable destination, DataTable source, IEnumerable<string> columnsToSkip)
{
if (columnsToSkip == null) columnsToSkip = new List<string>();
foreach (var col in source.Columns.OfType<DataColumn>().Where(col => !columnsToSkip.Contains(col.ColumnName)))
{
var newCol = destination.Columns.Add(col.ColumnName, col.DataType);
newCol.AllowDBNull = true;
destination.Rows[0][newCol] = source.Rows[0][col];
}
}
MergeColumns(custTable, orderTable, new string[] { "CompanyID" });
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.