How to eliminate all dublicate rows based one coloum name"commentname"

Data table

+----+---------+-------------------+-------------+
| id | title   | email             | commentname |
+----+---------+-------------------+-------------+
|  3 | test    | rob@hotmail.com   | rob         |
|  4 | i agree | rob@hotmail.com   | rob         |
|  5 | its ok  | rob@hotmail.com   | rob         |
|  6 | hey     | rob@hotmail.com   | rob         |
|  7 | nice!   | simon@hotmail.com | simon       |
|  8 | yeah    | john@hotmail.com  | john        |
+----+---------+-------------------+-------------+

expected Dt

+----+-------+-------------------+-------------+
| i email             | commentname |
+----+-------+-------------------+-------------+
|  simon@hotmail.com | simon       |
|  john@hotmail.com  | john        |
+----+-------+-------------------+-------------+

Blockquotedt.AsEnumerable().GroupBy(Function(i) i.Field(Of String)(“ColumnName”)).Select(Function(g) g.First).CopyToDataTable()

issue in this code is it gives one dublicate row can some one modify to remove all duplicates based on commentname coloumn

Have you tested to insert a Where(Function(g) g.Count = 1) in between?

dt.AsEnumerable().GroupBy(Function(i) i.Field(Of String)("commentname")).Where(Function(g) g.Count = 1).Select(Function(g) g.First).CopyToDataTable
1 Like

other way
(From r In dt.AsEnumerable()
Group By r = r.Field(Of String)(“commentname”) Into g = Group, Count
Where g.Count = 1
Select g.First).CopyToDataTable

2 Likes

thanks @park363 @ptrobot

Of String >>convert to>>>Of Object and it worked

1 Like

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