DataTable判斷某個字段是否有重複數據、數組去重複。

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章