去掉DataTable重复行

DataTable table = new DataTable();
                DataColumn[] columns = new DataColumn[] {
                new DataColumn("id",typeof(int)),
                    new DataColumn("name",typeof(string)),
                    new DataColumn("code",typeof(string)),
                };
                table.Columns.AddRange(columns);
                //去掉重复行
                DataView dv = table.DefaultView;
                table = dv.ToTable(true, new string[] { "name", "code" });

 

 

此时table 就只有name、code无重复的两行了,如果还需要id值则

table = dv.ToTable(true, new string[] { “id”,"name", "code" });

你可能感兴趣的:(小结,string,table)