/// /// Adding all the rows of an incoming table to an existing table, where the columns may be mismatched, and dropping source values that don't match the destination is ok. /// /// /// 09.19.10 LW: Altered the Row add line from import to Rows.Add. Method works now >.> /// 09.05.10 LW: Created. Posted online http://blog.leviwatts.com/2010/09/import-mismatched-table.html /// /// Table to be added to destination table /// Table to be receive to source table public static DataTable AddTableToTable(DataTable dtSource, DataTable dtDestination) { DataRow drInsert; foreach (DataRow drSource in dtSource.Rows) { //For each row in the source table, add any values that match in the destination table drInsert = dtDestination.NewRow(); foreach (DataColumn dc in dtDestination.Columns) { if (dtSource.Columns.Contains(dc.ColumnName)) { drInsert[dc.ColumnName] = drSource[dc.ColumnName]; } } dtDestination.Rows.Add(drInsert); } return dtDestination; }