过滤DataTable中的重复数据根据列名来过滤
废话少说,网上找了,后来又自己写了,直接上代码了:
// 过滤datatable中重复的信息 public DataTable GetDisTable(DataTable oldTable) { if (oldTable != null || oldTable.Rows.Count>0) { DataView view = new DataView(oldTable); string []discolom = new string[]{"Content"}; // 如果过滤每个字段的话就下面 //string[] discolom = new string[ oldTable.Columns.Count]; //foreach (DataColumn dc in oldTable.Columns) { // discolom[dc.Ordinal] = dc.ColumnName; //} DataTable nTable = new DataTable(); nTable = view.ToTable(true, discolom); nTable.Columns.Add("FSelected", typeof(bool)); foreach (DataRow dr in nTable.Rows) { dr["FSelected"] = false; } return nTable; } return null; }
本文来自博客园,作者:十四,转载请注明原文链接:https://www.cnblogs.com/yanghucheng/archive/2012/11/23/2784805.html