I want to remove duplicate rows from datatable by comparing single column

@qbss

  1. Lets consider your table as, dtTable

  2. First try getting all the duplicate rows,
    dtDuplicateTable = dtTable.AsEnumerable().GroupBy(Function(dr) dr.Field(Of String)(“Claim_No”)).Where(Function(g) g.Count() > 1).SelectMany(Function(g) g).ToList().CopyToDataTable

  3. Now compare the original table with duplicate table and exclude the duplicate rows from original table,
    dtFinalTable = dtTable.AsEnumerable().Except(dtDuplicateTable.AsEnumerable, DataRowComparer.Default).CopyToDataTable

P.S: Check for record existence before converting as CopyToDataTable while doing complete implementation. Otherwise, if there are no records found, the statement will through exception.

Let me know if this works for you.

2 Likes