C# DataTable 3种 Distinct 方法
//1.根据Order_No、Client_Code 两个字段去重,distinct之后的table只保留括号内写的字段
DataTable DtHeadDis = DtEntities.DefaultView.ToTable(true, "Order_No", "Client_Code")
//2.根据字段Ord_OrderNo去重,字段可以加,distinct之后的table保留全字段
var dt=DtHeadNow.AsEnumerable().ToList();
DataTable DtNewHead = dt.Where((x, i) => dt.FindIndex(z => z["Ord_OrderNo"] == x["Ord_OrderNo"]) == i).CopyToDataTable();
//3.手动筛选
DataTable DtHeadDis = DtHead.Clone(); foreach (DataRow item in DtHead.Rows) { DataRow[] drs= DtHeadDis.Select("Client_Code='" + item["Client_Code"].ToString() + "' and Order_No='" + item["Order_No"].ToString() + "'"); if (drs.Count() == 0) { DtHeadDis.ImportRow(item); } } foreach (DataRow Row in DtHeadDis.Rows) { Row.AcceptChanges(); Row.SetAdded(); }