How to get duplicate rows for specific column in a datatable

Hi,

Please find the reference, DataTable filtering with expressions

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

@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

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

12 Likes

@arivu96 thanks :slight_smile:

2 Likes