Duplicate value in a colum

Hi,
I need to check if there are any duplicate values in a column(colB) if there are in need to send a message box displaying the value duplicated.
How do i do that?

Hi @RACHEL_PAUL

Duplicate records from the same data table
(From p in dt.Select() where( From q in dt.Select() where string.Join(",",q.ItemArray).Equals(string.Join(",",p.ItemArray)) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()

Try this one
If you want specific Column alone mention the column name
(From p in dt.Select() where( From q in dt.Select() where q("ColumnName").Equals(p("ColumnName")) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()

Whats p and q?

@RACHEL_PAUL “p” and “q” are row

Hi @RACHEL_PAUL
are you get desirable solution?

1 Like

Hello @RACHEL_PAUL

DuplicateValues = YourDatatable.AsEnumerable().Select(Function (a) a.Field(of string)(“yourcolumnname”).ToString).ToArray().GroupBy(Function(x) x).Where(Function(y) y.Count() > 1).ToList()

YourDatatable is the datatable
yourcolumnname is your column name

In the above case you can get duplicates into a list. Or you can watch the below video for datatable based approach.

Thanks

Thank you.

@RACHEL_PAUL Welcome and Happy Learning

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.