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.
First read both the tables from Excel file and let’s say dtInput1 and dtInput2.
And then try below query.
dtOutput = dtInput1.AsEnumerable().Except(dtinput2.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable
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…
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 ?
Try below expression.
dtOutput = ( From row1 in dtInput1
Join row2 in dtInput2
On Not row1("Id").ToString.Trim.Equals(row2("Id").ToString.Trim)
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))
Many thanks @ppr, it is working
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?
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.