Compare 2 column values and delete identical rows through LINQ

Hello,
I have 1 data table such as dt1dt1

I want to remove rows where ID and Name both have same values. I wanna achieve it applying LINQ code.

Output should be 1st and 4th row.

Please help.
Thank you

1 Like

Hi @Chand

First the links that support this answer: here and here.

The query would look like that:
From r In yourDataTable
Group By Distinct = New With {Key .ID = CInt(r(“ID”)), Key .Name = CStr(r(“Name”))} Into Group
Where Group.Count = 1
Select Distinct

The second link gives clues how to convert the LINQ result into a Data Table.

3 Likes

In this case you can use standard datatable features.

Assign DistinctDt = dt.DefaultView.ToTable(“Test”, True, “ID”, “Name”)

Sorry, @Chand I’ve misread your requirments in first comment. But your can solve it with one liner here if we extending above solution of @loginerror

Assign newDt =
(From r In yourDataTable
Group By Distinct = New With {Key .ID = CInt(r(“ID”)), Key .Name = CStr(r(“Name”))} Into Group
Where Group.Count = 1
From g In Group
Select g
).CopyToDatatable

2 Likes

And the workflow as xaml file, just because I wanted to test it myself so I might as well post it :slight_smile:
DistintRows.zip (12.4 KB)

When uploading the xaml files please do not zip. Its blocked in some organizations.

1 Like

Fair remark. I am not sure if it is always feasible though. In this case, maybe, because there are three files in the package which could have been uploaded separately:
DistintRows.xaml (6.6 KB)
InputFile.xlsx (8.1 KB)
OutputFile123.xlsx (7.1 KB)

However, it gets tricky if we need to share a ReFramework project.

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