DataTable判断某个字段是否有重复数据,数

2025-01-05 15:01:06
推荐回答(1个)
回答1:

//1.DatatTable 某个字段是否重复
DataTable dtTableDisinit = (DataTable)this.c1TrueDBGrid1.DataSource;
                DataView dv = new DataView(dtTableDisinit);
                if (dv.Count != dv.ToTable(true, "PMD_SingProduct").Rows.Count)
                {
                    Common.showMessageInfo("网格中存在重复的品番!");
                    return;
                }
//2.数组中去重复的数据和判断一个数组中是否有重复的数据
 string[] strSing = this.PM_CollectionGoods.Text.ToString().Trim().Split(',');
            string[] strDis = strSing.Distinct().ToArray();
            if (strSing.Length != strDis.Length)
            {
                Common.showMessageInfo("数组中存在重复的数据");
                return;
            }