Ananth Ananth - 1 year ago 92
C# Question

Best way to remove duplicate entries from a data table

What is the best way to remove duplicate entries from a Data Table?

Answer Source

Remove Duplicates

public DataTable RemoveDuplicateRows(DataTable dTable, string colName)
   Hashtable hTable = new Hashtable();
   ArrayList duplicateList = new ArrayList();

   //Add list of all the unique item value to hashtable, which stores combination of key, value pair.
   //And add duplicate item value in arraylist.
   foreach (DataRow drow in dTable.Rows)
      if (hTable.Contains(drow[colName]))
         hTable.Add(drow[colName], string.Empty); 

   //Removing a list of duplicate items from datatable.
   foreach (DataRow dRow in duplicateList)

   //Datatable which contains unique records will be return as output.
      return dTable;

Here Links below

For remove duplicates in column

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download