Hi Team,
How to get only duplicate value in DT Table.
Input DT:
| Name |
DOB |
ID |
| Kohli |
01-12-1981 |
1 |
| Sandeep |
01-12-1981 |
2 |
| Rahul |
01-12-1981 |
3 |
| Kohli |
27-01-1996 |
4 |
| Sandeep |
01-12-1981 |
5 |
| David |
20-01-2000 |
6 |
| Rahul |
01-12-1981 |
7 |
Output DT:
| Name |
DOB |
ID |
| Sandeep |
01-12-1981 |
2 |
| Sandeep |
01-12-1981 |
5 |
| Rahul |
01-12-1981 |
3 |
| Rahul |
01-12-1981 |
7 |
I need Duplicate Values.
Please help me to resolve this issues.
Thanks,
Copywrite
Parvathy
(PS Parvathy)
2
Hi @copy_writes
Try this:
duplicateRows = dt.AsEnumerable().
GroupBy(Function(row) New With {
Key .Name = row.Field(Of String)("Name"),
Key .DOB = DateTime.ParseExact(row.Field(Of String)("DOB"),"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture)
}).
Where(Function(Group) Group.Count() > 1).
SelectMany(Function(Group) Group).
CopyToDataTable()
Hope it helps!!
1 Like
Parvathy
(PS Parvathy)
3
Hi @copy_writes
=> Read Range Workbook. Enable Preserve Format option.

Output-> dt
=> Use below syntax in Assign:
duplicateRows = dt.AsEnumerable().
GroupBy(Function(row) New With {
Key .Name = row.Field(Of String)("Name"),
Key .DOB = DateTime.ParseExact(row.Field(Of String)("DOB"),"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture)
}).
Where(Function(Group) Group.Count() > 1).
SelectMany(Function(Group) Group).
CopyToDataTable()
duplicateRows is of DataTyps System.Data.DataTable
=> Write Range Workbook

Hope it helps!!
1 Like
Parvathy
(PS Parvathy)
4
Hi @copy_writes
If you find the solution for the query, please mark my post as solution to close the loop or if you have any questions, I’m happy to help.
Regards
Use this linq:-
duplicateNames = dt_input.AsEnumerable() _
.GroupBy(Function(row) row.Field(Of String)(“Name”)) _
.Where(Function(group) group.Count() > 1) _
.Select(Function(group) group.Key)
system
(system)
Closed
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.