Best way to remove duplicate entries from a data table

DataTable dtIds = GetReservationIds(dtAllReservations);

var duplicates = dtIds.AsEnumerable().GroupBy(r => r[0]).Where(gr => gr.Count() > 1).ToList();

if(duplicates.Any())Console.WriteLine("Duplicate found for Classes: {0}",String.Join(", ", duplicates.Select(dupl => dupl.Key)));
string ceva = String.Join(", ", uniqueIds.AsEnumerable().Select(x => x[0].ToString()));

var UniqueRows = dtIds.AsEnumerable().Distinct(DataRowComparer.Default);
DataTable dt2 = UniqueRows.CopyToDataTable();


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s