合并2个DataTable
DataTable DataTable1 = SqlHelper.GetDataTable("select convert(char(5),id) As 'id' ,num from testSum"); DataTable DataTable2 = SqlHelper.GetDataTable("select '统计',Sum(num) from testSum"); 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); } GridView1.DataSource = newDataTable; GridView1.DataBind();