2
Answers

How to check Duplicate value in Data table's Rows?

Raja

Raja

8y
322
1
In data table In three rows value given below
 
1 2 3 4 5 6 7 8
9
10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
 
 
I will check duplicate value occur. like if 2 is occur in two times show the validation message.like Duplicate value occured.
if (ds.Tables[s].Rows[0][i].ToString().Trim() == "")
{
dt.Rows.Add();
dt.Rows[mn][0] = "Tag Number Should Be Mandatory" +ds.Tables[s].TableName; 
}
Above code i will check if the empty filed occur in table show the mandatory message.Now i want to validate duplicate value occur.
Answers (2)
0
Bikesh Srivastava

Bikesh Srivastava

NA 19.8k 835k 8y
try this ,
  1. Hashtable hTable= new Hashtable();
  2. foreach(DataRowdrowindTable.Rows)
  3. {
  4. if(hTable.Contains(drow[colName]))
  5. duplicateList.Add(drow);
  6. else
  7. hTable.Add(drow[colName],string.Empty);
  8. }
Accepted
0
Raja

Raja

NA 1.7k 45.4k 8y
<h4><a data-userid="895c53" href="http://www.c-sharpcorner.com/members/bikesh-srivastava2">Bikesh Srivastava</a></h4><div>I want to show the Validation message like "Duplicate value enter" how to do it?</div><div></div><div>:( </div>