Update datatable using linq with where clause

I am trying to achieve the below statement using LINQ statement. Can someone help me to write the correct statement in UiPath

update table xyz set [Column A]=1 where [Column B] in (10,20,30)

Have a look on the various options to do a column update here:

How to Update Data Column Values of a Data Table | Community Blog

I did refer to the link. It is looping using for each row.
I looking to update the same using linq statements.

it is also listing

  • 1.4 LINQ Approach - introducing the itemArray Construction Approach
  • 1.2 Invoke Code Approach which can be extended by a filtering used in 2.1

As we cannot use LINQ for direct Column Value update within an Assign Actrivity, we could select the invoke code approach. Using the invoke code we can mirror the for each as described in 1.2

using a LINQ like dtData.AsEnumerable.Where(…).toList().ForEach(…) would be similar as doing it directly on the mirrored Invoke Code.

And as discussed in the conclusion there must be a valid reason why preferred for each row cannot be used. The argument “many rows” is not strong enough in the most cases.

1 Like

Can you please explain it more in details? Maybe with example from Excel or something else?

You have two columns in the table: A and B
And you want to update the Column A, if the Column B is one of these values: 10 or 20 or 30
Did I understand you correct?

From row in Excel_DT
Where row("ColumnB").ToString.Trim = "10" or row("ColumnB").ToString.Trim = "20" or row("ColumnB").ToString.Trim = "30"
Let row("ColumnA").ToString = "1"
Select Excel_DT
1 Like