过滤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;
        }

 

posted @ 2012-11-23 17:30  十四  阅读(875)  评论(0编辑  收藏  举报