I have seen the following solution used for removing duplicate rows in a DataTable
using LINQ
:
Say if we have a DataTable
with duplicate rows called dt
, then the following statemend apparently does the job:
IEnumerable<DataRow> uniqueContacts = dt.AsEnumerable().Distinct(DataRowComparer.Default);
But this is only removing duplicate rows that are identical. What I want to do is to remove all the rows that have duplicate values of a specific row.
E.g. If we have a datatable with a row called "Email", how can we remove all the rows that have the same email value?
simple way: use
GroupBy
:you can also try use
Distinct
:Custom row comparer:
http://msdn.microsoft.com/en-us/library/bb338049.aspx