Problem: Find duplicates in DataTable object (VB.Net)

Problem: Find duplicates in DataTable object (VB.Net)

Hi.

I have a datatable (not a database table just the object datatable in VS.Net) (Dim dt as Datatable)

this datatable has 10 columns call them C1, C2, C3 … C10

I like to check if there are any records in this table that has the same values in C1 C2 and C3 and then sort them out to another table.

The data is read from a CSV file and not a databse so I can’t solve this in a database I nned to do it with code.

So I need one table with all the data that has no duplicate
and the other with all dupilcates

Ex

there are two rows that has same data on C1,C2 and C3, these TWO rows go to duplicatesTable the other rows go to DistinctTable.

How can I solve this..


Solution : Find duplicates in DataTable object (VB.Net)

Something like this?

Dim CountOfRows As Integer
Dim dtDistinct As DataTable = dtSource.Clone
Dim dtDuplicates As DataTable = dtSource.Clone
For Each dr As DataRow In dtSource.Rows
CountOfRows = dtSource.Compute(“Count(C1)”, “C1 = ” & dr(“C1″) & ” AND C2 = ” & dr(“C2″) & ” AND C3 = ” & dr(“C3”))
If CountOfRows > 1 Then
dtDuplicates.Rows.Add(dr.ItemArray)
Else
dtDistinct.Rows.Add(dr.ItemArray)
End If
Next

Substitute your table name for dtSource.