两个结构一样的DataTable合并
DataTable DataTable1 = new DataTable(); DataTable DataTable2 = new DataTable(); DataTable newDataTable = DataTable1.Clone(); object[] obj = new object[newDataTable.Columns.Count]; for (int i = 0; i < DataTable1.Rows.Count; i++) { DataTable1.Rows[i].ItemArray.CopyTo(obj,0); newDataTable.Rows.Add(obj); } for (int i = 0; i < DataTable2.Rows.Count; i++) { DataTable2.Rows[i].ItemArray.CopyTo(obj,0); newDataTable.Rows.Add(obj); } //或者 DataTable DataTable1 = new DataTable(); DataTable DataTable2 = new DataTable(); object[] obj = new object[DataTable1 .Columns.Count]; for (int i = 0; i < DataTable2.Rows.Count; i++) { DataTable2.Rows[i].ItemArray.CopyTo(obj,0); DataTable1.Rows.Add(obj); }
1.DataTable DataTable1 = new DataTable();
2.DataTable DataTable2 = new DataTable();
3.DataTable newDataTable = DataTable1.Clone();
4.
5.object[] obj = newobject[newDataTable.Columns.Count];
6.for (int i = 0; i < DataTable1.Rows.Count; i++)
7.{
8. DataTable1.Rows[i].ItemArray.CopyTo(obj,0);
9. newDataTable.Rows.Add(obj);
10.}
11.for (int i = 0; i < DataTable2.Rows.Count; i++)
12.{
13. DataTable2.Rows[i].ItemArray.CopyTo(obj,0);
14. newDataTable.Rows.Add(obj);
15.}
16.//或者
17.DataTable DataTable1 = new DataTable();
18.DataTable DataTable2 = new DataTable();
19.
20.object[] obj = newobject[DataTable1 .Columns.Count];
21.for (int i = 0; i < DataTable2.Rows.Count; i++)
22.{
23. DataTable2.Rows[i].ItemArray.CopyTo(obj,0);
24. DataTable1.Rows.Add(obj);
25.}
两个结构不同的DataTable合并