日期:2010-01-03 浏览次数:20455 次
两个结构一样的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);
- }
- 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++)
- {