I have a dataTable with 3 columns Column1, Column2 and Column3 with 100 rows.
Column1 Column2 Column3
123 hello GoodMorning
765 heloon GoodNight
134 hey GoodEvening
123 hi GoodEvening
I wanted to replace the values of all rows in Column1 based on some condition.
Example : Replace the value with new value “1234” if the existing value is “123”
Or Replace the value with new value “1234” if the eixsting value is >120
Use a assign activity like this if we know which column values we want to replace
dt = dt.AsEnumerable().Where(Function(a) a.Field(of string)(“yourcolumnname”).ToString.Replace(“your old value”,” your new value”).ToString).CopyToDatatable()
But this is giving me an error in Uipath studio :
Option Strict On disallows implicit conversions from 'String' to 'Boolean'.
Follow the steps belo:-
Take one read range output as-> dt_out
Take one Assign activity Create a int veriable->Counter
Take one for each row in Data table → pass the dt_out
Take one if condition. Mention the condition like this:
In Then Part :
Take one Assign Activity - Create string variable DataReplace
DataReplace = CurrentRow("ColumnName").ToString.Replace("123","1234").ToString
Take one write cell activity…
Pass the value as DataReplace in the range mention
Take one Assign activity
In Else part:- Take one Continue activity
Try this and let me know
Thanks for the response. But my question is to perform modification with out for loop.
in the case of 100 rows, we don’t see any blocker for using for each row activity.
For an overview of the different options we do have find the following blog link:
How to Update Data Column Values of a Data Table | Community Blog
when all rules are fixed and defined, then we can give more details on an alternate solution approach
as the Where operator is expecting a boolean return from the Lambda function there will be a missmatch with the returned string from the replace method. Therefore we do get a validation error.
Also we do need a return value from every step we do formulate within the LINQ. That’s the reason why some constructs e.g. row(ColNameOrIndex) = “ABC” will not work within the assign activity.
LINQ is part of the .NET framework and offers capabilities for interacting with data, objects or other sources within a particular syntax.
This HowTo introduces on starting with LINQ (Language-Integrated Query).
Current Version of this topic is DRAFT and will be finalized / enhanced soon
Typical tasks for implementing parts of an automation project are interacting with e.g. with data in a datatable or items from collections. LINQ can help to implement it into a compact and stand…