去除DataTable中的重复数据
有时需要从DataTable中抽取Distinct数据,遍历比较费劲,C#.NET中其实有更易用的方法,如下:
string[] columnArray = { "columnName1", "columnName2" };
DataView dataView = dataTable.DefaultView;
dataTable = dataView.ToTable(true, columnArray);
或者
DataView dataView = dataTable.DefaultView;
dataTable = dataView.ToTable(true, "columnName1", "columnName2");
ToTable的去重方法定义如下:
public DataTable ToTable(bool distinct, params string[] columnNames);
public DataTable ToTable(string tableName, bool distinct, params string[] columnNames);