Hello Lucius,
Thanks for Benny's response.
DataTable.Merge() method merge two tables by Primary key.
In your case, the table that has to be merged needs the same primary key as
the destination table.
For example:
System.Data.DataTable dt1 = new System.Data.DataTable();
dt1.Columns.Add("c1");
dt1.Columns.Add("c2");
dt1.PrimaryKey = new System.Data.DataColumn[] { dt1.Columns[0]};
dt1.Rows.Add(new object[] { 1, 1 });
dt1.Rows.Add(new object[] { 2, 2 });
dt1.Rows.Add(new object[] { 3, 3 });
System.Data.DataTable dt2 = new System.Data.DataTable();
dt2.Columns.Add("c1");
dt2.Columns.Add("c2");
dt2.PrimaryKey = new System.Data.DataColumn[] { dt2.Columns[0]
};
dt2.Rows.Add(new object[] { 1, 4 });
dt2.Rows.Add(new object[] { 2, 5 });
dt2.Rows.Add(new object[] { 3, 6 });
dt1.Merge(dt2);
Result: dt1
C1, C2
1,4
2,5
3,6
Hope this helps. If there is anything unclear, please feel free to update
here. I'm glad to assit you.
Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.