两个Datatable合并
两个结构一样的DataTable合并
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合并