Use list to check for duplicates in a datarow

1 comments

If you are walking through a dataset or datarow printing things out, you can skip duplicates by using a list to keep track of what you have done so far.

var dupcheck = new List<string>();
foreach (DataRow dr in dt.Rows)
{
     //rowIndex++;
     string partNumber = dr[1]+"";
     if(dupcheck.Contains(partNumber)) continue;		//skip duplicate
     dupcheck.Add(partNumber);
     //print out the partnumber 
} 

Comments


Leave a Comment