LINQ syntax filter and update lines


I have a large datatable and I want to filter it by condition Col2 = “B” and update the resulted lines on Col3 whit “yes”
Col1 Col2 Col3
A B -
A E -
A B -
A D -
A B -

The result:

Col1 Col2 Col3
A B yes
A E -
A B yes
A D -
A B yes

I’m trying to avoid for each or other kind of loop activity.
Many thanks in advance!

The LINQ concept is less intended for such an update task. We could do it by following:

  • for each activity with filtered input - filtering done with a LINQ
  • Invoke Code
  • A LINQ reconstructing the datatable with also calculated Col3 value

Instead of updating Col3 with a LINQ we can use the Expression functionality of datacolumn

Expression: “IIF([Col2]=‘B’, ‘yes’,‘’)”

A Benefit is that the Col3 value will always be correct also after Col2 value updates

Find starter help here:
DCExpression_SetConditionalValue.xaml (7.0 KB)


Hi @drago47

Please use the below Linq Expression

(From d In builDt.AsEnumerable
Let u = If(d(1).toString.Trim.Equals(“B”),“Yes”,“”)
Select DtResult.Rows.Add(New Object(){d(0),d(1),u})).CopyToDataTable

Modified the solution provided by @ppr

And also refer the thread below…

Refer to the xaml below!
test.xaml (8.2 KB)


1 Like

@pravin_calvin , @ppr thanks a lot, guys, for the quick responses! I will come back with feedback and solution!

Brilliant solution! I wasn’t aware of the columns expression method! I have marked @pravin_calvin answer as a solution because I’m more interested in the linq approach. Again, many thanks - simple and elegant solution!
p.s. I’ve read your previous answers on similar topic [LINQ query to update(replace)datatable in uipath] - really well documented.

Thanks for the solution. Is the approach I much needed! Great job @pravin_calvin

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