C# uses Linq to implement DataTable to implement duplicate data filtering

黄舟
Release: 2017-02-18 10:21:04
Original
2550 people have browsed it

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);  
                });
            }
Copy after login
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)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!