Working with Duplicates DataTables

Hi everyone,

I have created a datatable with col. (FileName [String], NewFileName [String], IsDuplicate [Boolean]).
I want to iterate through the DtTbl to find duplicate values in NewFileName. Each a duplicate NewFileName is found I want to set the Col. IsDuplicate to True for all rows which has the duplicated NewFileName.

I am at a loss of how I can achieve this, I appreciate any help that you can give.

Many thanks


Here, do you want to compare filename and newFileName columns to find duplicates ?

Just the NewFileName column as the FileName column should already be unique

With a dataview object you can select automically only the unique rows.

You see this in an onder post How to read next column

Group rows by NewFileName, then for groups with more than 1 element set flag to true.
Something like this (can’t check syntax but should get you on track):

Foreach row in yourDT.AsEnumerable().GroupBy(Function(dr) dr.Field(Of String)("NewFileName")).Where(Function(grp) grp.Count > 1).Select(Function(grp) grp.Value)

row.Field(Of Boolean)("IsDuplicate") = True