判断一表中的字段是否在另一表中存在

foreach (DataRow dr in dtQuery.Rows)
                        {
                            if (Convert.ToBoolean(dr["xz2"].ToString()))
                            {
                                //drcm = dt.Select("AccountName=" + dr["AccountName"].ToString());
                                //if (drcm.Length > 0)
                                //{
                                //    Common.AdCommon.ShowError("帐户为"+dr["AccountName"].ToString()+"的帐户已在店帐户中存在");
                                //    return;
                                //}

                                DataView dvTable2 = new DataView(dt);
                                dvTable2.Sort = "AccountName ";
                                int i = 0;
                                while (i < dt.Rows.Count)
                                {
                                    if (dvTable2.Find(dr["AccountName"].ToString()) > -1)
                                    {
                                        Common.AdCommon.ShowError("帐户为" + dr["AccountName"].ToString() + "的帐户已在店帐户中存在");
                                        return;
                                    }
                                    else
                                        i++;
                                }
                            }
                        }

你可能感兴趣的:(判断)