Hi,
How does DataTable remove duplicate rows work?
How does duplicate row gets determined? A column or all columns?
Thank you,
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
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
dt.AsEnumerable.GroupBy(Function(a) Tuple.Create(a("CName").ToString,a("Cname").ToString)).Select(Function(b) b.First).CopyToDataTable
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
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.