Compare Two Excel Using Linq

I want to compare 2 DT using linq, DT2 compare to DT1, when the column WSID is match, value from Nominal will write from DT2 to column KWW in DT1 and when Nominal is null or empty, the value is set to " "
Where DT1 is


and DT2

Now I using for each row inside a for each row, but the process is take a long time. Thanks for the reply and have a nice day!

Give a try on
(From d1 In dt1.AsEnumerable
Join d2 In dt2.AsEnumerable
On d1(“WSID”).toString.trim Equals d2(“WSID”).toString.trim
Select d1).CopyToDatatable

Thanks for reply, I have tried but the result is not what I expect, I want to compare DT2 to DT1 and Write the Nominal value in the DT1

Have a look at the following post. For LINQ the datatable reconstruction approach is presented:

You can do the same thing by joining two tables (Left join) and then removing empty rows from the table.

And if required you can change column names also.

2 Likes

DT.asenumerable.Tolist.Foreach(Sub(r) r(“yourColumnname”)=“”).Copytodatatable

Thank you for reply! I’ll try it, have a nice day

Thank you for reply, join DT2 to DT1?

Thank you for reply, I’ll try it, have a nice day

No, join DT2 into DT1 using left join.

3 Likes