Home > Article > Backend Development > C# uses Linq to implement DataTable to implement duplicate data filtering
Before filtering:
##After filtering(only filtered out Exactly the same data) :
##The code is as follows:
##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);
});
}
The above is the content of C# using Linq to implement DataTable to implement duplicate data filtering. For more related content, please pay attention to PHP Chinese website (www.php.cn)!