Hello All,
I want to update datatable .It has multiple columns, basis on one column need to update second column using linq.
Can anybody help me with linq ?
Regards,
Akanksha
Hello All,
I want to update datatable .It has multiple columns, basis on one column need to update second column using linq.
Can anybody help me with linq ?
Regards,
Akanksha
@akanksha.patil630 - Can you please elaborate?
I have a data table with 50K records. I want to update one column value basis on another column value like shown below.
IF the value of âShiftâ Column is âMSPâ, I want to update âTag_Shiftâ Column as âMSP-MOBâ.
You can try below steps -
Let me know if any issue.
@parasmanichauhan solution will work for what you need, if you want to explore using Linq I have provided it below but you will have to adjust it within UiPath.
var rowsToUpdate =
Datatable.AsEnumerable().Where(r => r.Field<string>("Shift") == "MSP");
foreach(var row in rowsToUpdate)
{
row.SetField("Tag_Shift", "MSP-MOB");
}
Or you can use Datatable.Select:
Datatable.Select("Shift='MSP'").ToList().ForEach(Sub(row) row("Tag_Shift")="MSP-MOB")
Thanks for reply @parasmanichauhan .
I am looking for linq as For each loop will take considerable time to execute.
Thank you @TimK , appreciate your response.
TimK,
I am trying your suggestion but I am getting a compile error âExpression does not produce a valueâ. I am trying this is Assign activity with the below suggestion of yours -
Datatable.Select(âShift=âMSPââ).ToList().ForEach(Sub(row) row(âTag_Shiftâ)=âMSP-MOBâ)
Not sure why. Could you help on this?
The reason of this ist that foreach ist a sub Routine and is Not returning a value. A Lot of linq Datatable Update cases can be done, but requires a different Handling.
WE can Help on this, but IT IS recommended to Open a seperate topic, so WE can Adress individually
Thanks @ppr. I have created a new topic for this error -
Hi all ,
I tried this using Invoke Code .FilterLinq.xaml (7.3 KB)
Hi Timk, @jeevith @ClaytonM I want to update two column into for each.
dt.AsEnumerable().Where(Function(row) row (âAvailableâ).ToString.Equals(âFindâ)).ToList().ForEach( Sub (row) row(âUpdateColâ) = âAction needâ; row(âFFâ) = âNo Actionâ)
In for each one column is working fine but when i pass two column it will return error.