Как проверить дубликаты данных для столбца в наборе данных в ASP.NET с помощью C#?
Я хочу проверить дубликаты данных для столбца в наборе данных в asp.net с помощью c#. Я читаю текстовый файл CSV, преобразую его в набор данных и назначаю объекту. мне нужно проверить наличие дубликатов записей.
Что я уже пробовал:
Код выглядит следующим образом:
foreach (OUT_500_DETAIL objOUT_500_DETAIL in objOUT_500_CONTROL.objOUT_500_DETAIL) { #region SponsoringBankSequenceNo if (string.IsNullOrEmpty(objOUT_500_DETAIL.SponsoringBankSequenceNo.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -Sponsoring Bank Trans Ref No Cannot be Empty"; } else { if (!Validation.IsNumeric(objOUT_500_DETAIL.SponsoringBankSequenceNo.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -Sponsoring Bank Sequence No Should be Numeric"; } } #endregion #region InstructionCode if (string.IsNullOrEmpty(objOUT_500_DETAIL.InstructionCode.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -InstructionCode is mandatory"; } else { if (!Validation.IsAlphabet(objOUT_500_DETAIL.InstructionCode.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -InstructionCode should contain only alphabets"; } if (objOUT_500_CONTROL.IsDirect == false) { if (objOUT_500_DETAIL.InstructionCode.ToString().Trim() != "AUTH") { Error += Environment.NewLine + "Row " + Count + " -InstructionCode should be AUTH"; } } } #endregion #region OriginatorIdentificationCode if (string.IsNullOrEmpty(objOUT_500_DETAIL.OriginatorIdentificationCode.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -Originator Identification Code cannot be empty"; } else { if (objOUT_500_DETAIL.OriginatorIdentificationCode.ToString().Trim().Length > 9) { Error += Environment.NewLine + "Row " + Count + " -Originator Identification Code should not be greater than 9 Characters"; } if (!Validation.IsNumeric(objOUT_500_DETAIL.OriginatorIdentificationCode.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -Originator Identification Code should be numeric"; } } #endregion #region MandateReference if (objOUT_500_DETAIL.MandateReference.ToString().Trim() == "") { Error += Environment.NewLine + "Row " + Count + " -Mandate Reference cannot be empty"; } else { if (objOUT_500_DETAIL.MandateReference.ToString().Trim().Length>23) { Error += Environment.NewLine + "Row " + Count + " -Mandate Reference Length should not be greater than 23 Characters"; } if (!Validation.IsNumeric(objOUT_500_DETAIL.MandateReference.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -Mandate Reference should be numeric"; } } #endregion #region Currency if (objOUT_500_DETAIL.CurrencyCode.ToString().Trim() != "AED") { Error += Environment.NewLine + "Row " + Count + " -Currency Code should be AED"; } #endregion #region ClaimedAmount if (objOUT_500_DETAIL.ClaimedAmount.ToString().Trim() == "") { Error += Environment.NewLine + "Row " + Count + " -Claimed Amount cannot be empty"; } if (!Validation.IsNumeric(objOUT_500_DETAIL.ClaimedAmount.ToString().Replace(".", "0"))) { Error += Environment.NewLine + "Row " + Count + " -Claimed Amount should be numeric"; } #endregion #region OriginatorAccountNumber if (objOUT_500_DETAIL.OriginatorAccountNumber.ToString().Trim() == "") { Error += Environment.NewLine + "Row " + Count + " -Originator Account Number cannot be empty"; } else { if (!Validation.IsAlphaNumericSp(objOUT_500_DETAIL.OriginatorAccountNumber.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -Originator Account Number should be numeric"; } } #endregion #region PayingBank if (objOUT_500_DETAIL.PayingBank.ToString().Trim() == "") { Error += Environment.NewLine + "Row " + Count + " -Paying Bank Value cannot be empty"; } else { if (!Validation.IsNumeric(objOUT_500_DETAIL.PayingBank.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -Paying Bank should be numeric"; } } #endregion #region Payer if (string.IsNullOrEmpty(objOUT_500_DETAIL.Payer.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -Payer Account No: cannot be empty"; } else { if (!Validation.IsAlphaNumericSp(objOUT_500_DETAIL.Payer.ToString().Trim())) { Error += Environment.NewLine + "Row " + Count + " -Payer Account No: should be alphanumeric"; } else { } } #endregion Count++; }