How to compare values of all cells in a datatable with eachother?

Hi everyone, I have a data table and I want to compare all the values of each cell with one another. If I find that there are duplicate data, i want to keep only the first appearance and delete the others. First table is the data table i have and the second is the output i’m looking for.
There will be more than 2 columns, this was just an example.
Thank you in advance!

Welcome to the forum

A basic implementation could look like this:



  • We are creating a List of unique column values:
    ListUniqueValues =
(From d In dtData.AsEnumerable
From v In d.ItemArray
Select x = v.ToString.Trim()).Distinct().ToList
  • loop over the rows
  • loop over the col values via row.ItemArray
    • for each was configured with:

When value was found the first time we do keep, but will also remove it from the check list:
ListUniqueValues = ListUniqueValues.Except({item.ToString.toString}).ToList


Tysm. It worked.

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