Wednesday, January 25, 2012

Finding Duplicate Rows in DataTable using Linq

var duplicates = dt.AsEnumerable()
                .GroupBy(r => new { a = r[0], b = r[1] })
                .Where(gr => gr.Count() > 1);
lbMsg.Text = "Duplicate Record found for Rows: " + String.Join(", ", duplicates.Select(dupl => dupl.Key));


//End

3 comments: