[ad_1]
The Problem
I have a datatable containing several columns and rows. One of these column names is “logon”. Some Rows in this datatable have the same column “logon”. For example 2 Rows with a “logon” of test123
. I need a new datatable containing only one of these 2 Rows (which one doesn’t matter).
The Question
How can I create a new datatable from the old datatable, with rows filtered out that have duplicate entry in column “logon”. The new datatatable should have the same structure / columns as the old one. So in theory the only thing that changes after filter is the RowCount gets less if there are Rows with duplicate “logon” matches.
What have I tried so far
-
Dim distinctDT As DataTable = myDT.DefaultView.ToTable(True, "logon")
–> Gives me just a datatable with one column (“logon)”. Although filtered for uniques, it only contains one Column –> If i pass in an array with all my column names, it doesn’t filter for unique values anymore -
Dim names = From row In myDataTable.AsEnumerable() Select row.Field(Of String)("Name") Distinct
–> Gives me an array of strings with the unique values –> I need a datatable with same columns as before
Thank you very much!
[ad_2]