DataTable去重

 

 

        protected DataTable RemoveRepeatRows(DataTable sourcedt)
        {
            DataTable dtResult = sourcedt.Clone();
            List<int> contentIDList = new List<int>();
            List<int> threadIDList = new List<int>();
            if (sourcedt != null)
            {
                foreach (DataRow item in sourcedt.Rows)
                {
                    int contentID = Convert.ToInt32(item["ContentID"]);
                    int threadID = Convert.ToInt32(item["ArticleID"]);
                    if (!contentIDList.Contains(contentID))
                    {
                        if (!threadIDList.Contains(threadID))
                        {
                            dtResult.ImportRow(item);
                            contentIDList.Add(contentID);
                            threadIDList.Add(threadID);
                        }
                    }
                }
            }
            return dtResult;
        }

 

posted on 2017-11-21 12:28  奔游浪子  阅读(79)  评论(0)    收藏  举报

导航