DataTable Remove duplicate rows

Hi,

How does DataTable remove duplicate rows work?
How does duplicate row gets determined? A column or all columns?

Thank you,

Hi @A_Learner

How do you want the duplicate columns to be determined.

If you want to remove duplicates from All columns then you can use below syntax:

dt = dt.DefaultView.ToTable(True, "columnname1", "columnname2")

Note: you have to mention how many column you have.

If you want to remove duplicates based on a specific column then, post that requirement, I will help you out with LINQ expression.

Regards

@A_Learner

Please refer this thread

Hi @A_Learner

If you have so many columns then below syntax should help you:

resultDt = inputDt.DefaultView.ToTable(True, inputDt.Columns.Cast(Of System.Data.DataColumn)().Select(Function(col) col.ColumnName).ToArray())

resultDt is of DataType System.Data.DataTable()

Regards

@A_Learner

dt.AsEnumerable.GroupBy(Function(a) Tuple.Create(a("CName").ToString,a("Cname").ToString)).Select(Function(b) b.First).CopyToDataTable

@A_Learner

It checks for all columns…if whole of row is same then the row is considered as duplicate

If you need partial then you need to use linq

cheers

1 Like

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