Use linq to get different values between two tables


Could someone help me to get all different values from dt1 to dt2. I need to check if data in column “id” from dt1 isn’t in column “id” from dt2, and put these values in a datatable.

There are a lot of rows, and that’s why I want to use linq. I am using vb.



  1. First read both the tables from Excel file and let’s say dtInput1 and dtInput2.

  2. And then try below query.

dtOutput = dtInput1.AsEnumerable().Except(dtinput2.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable
1 Like

Isitabout the id values only you Wang to calculate or are you Interesses in entire rows from one of the datatable?

Sorry, i didn’t explain that there are more columns, and dt1 contains 10 columns, and dt2 contains 2 columns. If I do this it gets me all rows…

Hello @ppr,

If id in dt1 is not in id in dt2, put all values from that row from dt1 in a new datatable. So I will get a datatable with the info that it is in dt1, but it is not in dt2


If Id is not match from dt1 table to dt2 table then do you want all rows from dt1 table only or dt2 table also ?

Hi @lakshman,

I just one dt1 rows :slight_smile:


Try below expression.

dtOutput = ( From row1 in dtInput1
Join row2 in dtInput2
On Not row1("Id").ToString.Trim.Equals(row2("Id").ToString.Trim)
Select dtOutput.Rows.Add({row1("Id"),row1("Column2"),...,row1("Column10")})

thanks for the fast reply!

But it is giving me this error:


“equals expected” at the end of the message

(From d1 In dt1.AsEnumerable
Where Not dt2.AsEnumerable.Any(Function (x) x(“ID”).toString.Trim.Equals(d1(“ID”).toString.Trim))
Select r=d1).CopyToDataTable

Many thanks @ppr, it is working :slight_smile:

In case there are no rows. It would give me an error. How can i modify the linq query so in case it is empty it doesnt throw an error?


[FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

1 Like

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