Comparing 2 DT With Linq

I want to compare 2 DT using linq, DT2 compare to DT1, when the column WSID is match, value from Nominal on DT2 will write to spesific column in DT1 (can change) 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!

You can do the same thing by joining two tables (Left join) and then removing empty rows from the table. Join DT2 into DT1 using left join.

And if required you can change column names also.

2 Likes

thanks for reply, but I have to set “Nominal” value in spesific column, how can I do it? now I using linq for get just a nominal value with WSID in DT1 order, and write range it to column I want

when you join two tables you will get all columns from both tables, you just need to rename the columns and delete not required columns.

3 Likes

ah I see, so just join 2 DT then get the column I need, remove not required, I get the idea, thank you

1 Like

Duplicate / Cross Reference:

1 Like

One of many options: create a LookUp Dictionary:

dictLK | Dictionary (Of String, String) =

dt2.AsEnumerable.ToDictionary(Function (x) x("WSID").toString.Trim, Function (x) x("Nominal").toString.Trim)

so the check can be done within a for each row loop

  • for the check we can use the dictionary containsKey method
  • for the empty Nominal check we can use: isNothing(), String.IsNullOrEmpty methods
  • updating DT1 can be done within an assign activity

in your other topic we shared with you some Blog introducing the different options for updating a column value. As also discussed we would recommend to start with the for each row, when it is about the column value updates.

1 Like

Hi, thank you for reply and explanation, my case is clear now, have a nice day!

Hi

please check this solution

Main.xaml (9.6 KB)

1 Like

Hi, thank you for reply, I will try your solution, thanks for the effort, have a nice day!

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