Compare 2 dataTable according to 1 specific column and take the rows which has different values

Hi, i need to compare 2 dataTable and the specific column.

First DataTable;

As you can see i have a cloumn named “Tutar”

Second DataTable;

i need to take rows which has different values in it as you can see in the pictures. And i want to do it with LINQ.

I used this one but didn’t work or couldn’t write properly.

dtFirst.AsEnumerable.Where(Function(row) dtSecond.AsEnumerable.Where(Function(row2) Convert.ToDouble(row.Field(of object)(“Tutar”)).Equals(Convert.ToDouble(row2.Field(of Object)(“Tutar”))) ).FirstOrDefault is Nothing).CopyToDataTable

could you help me on that?

Here are two videos about comparing two datatables. Could help you further.
Compare with C#: UiPath | Compare Two Datatables in UiPath with C# Code | Compare Collections with C# | Comparing - YouTube
Compyre with LINQ: UiPath | Compare Two DataTables with LINQ | Function Intersect | Function Except | Function Union - YouTube

Best regards

1 Like

Give a try on following

(From d in dtFirst.AsEnumerable
Where Not dtSecond.AsEnumerable.Any(Function (x) x(“Tutar”)toString.Trim.Equals(d(“Tutar”)toString.Trim)
Select r = d).toList

LINQ is taking row from dtFirst if there is no row in dtSecond with a same Tutar value
Check is done on string base if needed we can also adopt it on double base

Handling defensive empty result have a look on this pattern:


Hi Mr. Peter,

gives me this error

Hi @Arif_Kilic
can u try this

output=(From r1 in dt1.AsEnumerable
From r2 in dt2.AsEnumerable
Where r1("Tutar").ToString<>r2("Tutar").ToString
Select r1).CopyToDataTable

output is a datatype of datatable.

Nived N
Happy Automation


The query gave me this result. do you have any idea what should i do to avoid copying?

Hi after this

Use remove duplicate rows activity to remove th duplicates


Nived N

Happy Automation

I did this but then recognized it gave me the same dataTable as the first dataTable

Is it possible to share sample excel file ?

Just have acheck on all opening and closing brackets and that every opened ist also closed

Give a try on


From d in dtFirst.AsEnumerable
Where Not dtSecond.AsEnumerable.Any(Function (x) x(“Tutar”)toString.Trim.Equals(d(“Tutar”)toString.Trim))
Select r = d).toList

Maybe in the where Line the Last closing one was ommited

unfortunately i couldn’t solve the problem

sample.xlsx (10.9 KB)

You will see here column named “Tutar” and “Oran”. i want to take only the different values according to the these columns

i made this workflow. it is working fine but i want to make it with LINQ methods.

do we had to compare by Oran or Tutar column can u explain that too please?

if you can do for the same row, both of those. but if you can’t at least “Tutar” would be good

I did not get that point @Arif_Kilic

ok. could you only consider for “Tutar” values

I run it but it seems that both sheets had different rows right?