代码如下:
合并:
/// <summary>/// 合并表结构相同datatable数据/// </summary>public DataTable Mergedata(){DataTable data = new DataTable();DataTable deptdata = new DataTable();data=DBHelper.FillDataTable(\"select * from T1\", null);deptdata=DBHelper.FillDataTable(\"select * from T2\", null);data.Merge(deptdata, true);return data;}
剔除重复数据:
/// <summary>/// 去除datatable重复数据/// </summary>public DataTable distinctdata(){DataTable data = new DataTable();DataTable distinctdata = new DataTable();List<string> datarowlist = new List<string>();string[] datarow;foreach (DataColumn row in data.Columns) //遍历出表头{datarowlist.Add(row.ToString());}datarow = datarowlist.ToArray();DataView dv = new DataView(data);distinctdata = dv.ToTable(true, datarow); //对表所有字段进行过滤,true表示使用distinct方法return distinctdata;}