How to get duplicate rows for specific column in a datatable

datatable

#1

Hi,

Please find the reference, DataTable

But the above reference code is removing the row instead of storing it in another datatable… How do I get the duplicate values using LINQ


#2

@Sunitha_Bist1

ListA=From m In((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).Select()
Select Convert.ToString(m.Item(“Column Name”)).ToList

or
dt2=(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

ListA=From p In dt2.Select
Select Convert.ToString(p.Item(“Column Name”)).ToList

Regards,
Mahesh


#3

HI @Sunitha_Bist1,

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()

Regards,
Arivu


#4

@arivu96 thanks :slight_smile: