0

I want to remove equal entries from DataTable. I tried DefaultView, but it only removes the equals and not all entries which including them.

DataView view = table1.DefaultView;
DataTable tbl = view.ToTable();
return tbl;
4b0
  • 21,981
  • 30
  • 95
  • 142
Nick S.
  • 11
  • 3

1 Answers1

0

you can do this

public DataTable RemoveDuplicate(DataTable dataTable, string columname)
{
  Hashtable hashTable = new Hashtable();
  List<String> duplicates = new List<String>();
 foreach (DataRow datarow in dataTable.Rows)
 {
   if (hashTable .Contains(datarow [columname]))
   {
    duplicateList.Add(datarow );
   }
   else
   {
    hashTable .Add(datarow [columname], string.Empty); 
   }
 }
  //Now remove the duplicates .
  foreach (DataRow datarow in duplicates )
  dataTable.Rows.Remove(datarow );
  return dataTable;
}
Haroon nasir
  • 648
  • 1
  • 7
  • 21