未过滤前:
过滤后(仅会过滤掉完全一样的数据):
代码如下:
DataTable dt = this.JsonToDataTable("[{\"Code\":\"SortId\",\"Name\":\"SortId\"},{\"Code\":\"SortCode\",\"Name\":\"编号\"},{\"Code\":\"SolutionName\",\"Name\":\"名称\"},{\"Code\":\"SortId\",\"Name\":\"SortId\"},{\"Code\":\"SortId\",\"Name\":\"SortId\"},{\"Code\":\"SortId001\",\"Name\":\"SortId\"}]"); DataTable dtSort = dt.Clone(); var query = from t in dt.AsEnumerable() group t by new { t1 = t.Field<string>("Code"),t2 = t.Field<string>("Name") } into m select new { code = m.Key.t1, name=m.Key.t2, rowcount = m.Count() }; if (query.ToList().Count > 0) { query.ToList().ForEach(q => { DataRow dr = dtSort.NewRow(); dr["Code"] = q.code; dr["Name"] = q.name; dtSort.Rows.Add(dr); }); }