Problem Mering DataSets
DataSet ds = new DataSet();
DataSet ds2 = new DataSet();
DataTable dt = new DataTable("Table1");
DataColumn dc = new DataColumn("Col1", typeof(int));
dt.Columns.Add(dc);
DataTable dt2 = new DataTable("Table1");
DataColumn dc2 = new DataColumn("col1", typeof(int));
dt2.Columns.Add(dc2);
DataColumn dc3 = new DataColumn("Col2", typeof(int));
dt.Columns.Add(dc3);
ds.Tables.Add(dt);
dt.PrimaryKey = new DataColumn[] { dc };
ds2.Tables.Add(dt2);
dt2.PrimaryKey = new DataColumn[] { dc2 };
DataColumn dc4 = new DataColumn("col2", typeof(int));
dt2.Columns.Add(dc4);
DataRow dr = ds.Tables[0].NewRow();
dr[0] = 1;
dr[1] = 2;
ds.Tables[0].Rows.Add(dr);
dr = ds2.Tables[0].NewRow();
dr[0] = 12;
dr[1] = 22;
ds2.Tables[0].Rows.Add(dr);
foreach (DataTable tdt in ds.Tables)
{
foreach (DataColumn tdc in tdt.Columns)
{
tdc.ColumnName = tdc.ColumnName.ToLower();
}
}
ds.Merge(ds2, false, MissingSchemaAction.AddWithKey);
This causes a key violation because it adds the columns in ds2 as new columns, even though the column names and ordinals match.
If you did the reverse, change ds2 to mtach ds column name, the merge works as expected.
Anyway around this? I would like to be able to change the target dataset (ds), instead of the source (ds2).
Thanks.

