How to remove the Duplicate Records from the Datatable based on Column

Nadeemshaik
Posted by Nadeemshaik under C# category on | Points: 40 | Views : 830
 public DataTable RemoveDuplicateRows(DataTable dTable, string colName)
{

try
{
Hashtable hTable = new Hashtable();
ArrayList duplicateList = new ArrayList();
foreach (DataRow dtRow in dTable.Rows)
{
if (hTable.Contains(dtRow[colName]))
duplicateList.Add(dtRow);
else
hTable.Add(dtRow[colName], string.Empty);
}
foreach (DataRow dtRow in duplicateList)
dTable.Rows.Remove(dtRow);
}
catch (Exception ex)
{
//
}
return dTable;
}

Comments or Responses

Login to post response