Datatable update based on column

I have a Datatable with the below details

Type Data
01 Bank
02 BankFin
03 BankAcc

Now if the type is 01- replace the Data from Bank to Banking
if the Type is 02-replace the data from BankFin to Bank Finance
How can we achieve this without using for each row, because i need to do this for bulk data

It can be done using Linq . can you try by the below post .

1 Like

@Priyanka_Ramesh thankyou for your reply.
But that is replacing the column based on that column values only.

Now my requirement is if A column is 01 i have to replace B column

Datatable.Select(“Type=‘01’”).ToList().ForEach(Sub(row) row(“Data”)=row(“Data”).toString.replace(‘Bank’,‘Banking’))

Datatable.Select(“Type=‘02’”).ToList().ForEach(Sub(row) row(“Data”)=row(“Data”).toString.replace(‘BankFin’,‘Bank Finance’))

1 Like

Can you try like this.

Hi @RachelN,

Can you try replacing the double and single quotes in UiPath?

Hello @RachelN,

Try replacing the single quotes in Bank Data and Bank Recon with double quotes. :slight_smile:


changed the Double Quotes.

Hi @RachelN,

Hmm… Instead of Assign activity can you call an Invoke Code activity instead?

Click on Edit Code then paste that query. Then click on Edit Arguments and add the testDT as input argument.

1 Like

Hi @jcastro
I am getting this error

Invoke code: Exception has been thrown by the target of an invocation.

Hi @RachelN,

Can you send a screenshot of the error?

RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.Data.SyntaxErrorException: Syntax error: Missing operand after ‘Type’ operator.
at System.Data.ExpressionParser.Parse()
at System.Data.DataExpression…ctor(DataTable table,
String expression,
Type type)
at System.Data.DataTable.Select(String filterExpression)
at UiPathCodeRunner_79dd36ec251a48b69e81856ee65e529b.Run(DataTable testDT)
— End of inner exception stack trace —
at System.RuntimeMethodHandle.InvokeMethod(Object target,
Object arguments,
Signature sig,
Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
Object parameters,
Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr,
Binder binder,
Object parameters,
CultureInfo culture)
at System.RuntimeType.InvokeMember(String name,
BindingFlags bindingFlags,
Binder binder,
Object target,
Object providedArgs,
ParameterModifier modifiers,
CultureInfo culture,
String namedParams)
at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object args)
at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode,
List1 inArgs, IEnumerable1 imps,
Object args)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance,
ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor,
BookmarkManager bookmarkManager,
Location resultLocation)

Thanks!

How about adding .ToString to row(“Data”) before the = sign. It should look like:

row(“Data”).ToString = row(“Data”).ToString.Replace……

Hi @RachelN,

Hmm… Ok. I have one last idea… maybe remove the "row(“Data”).ToString = " and leave the row(“Data”).ToString.Replace……

Sorry this is the first time I’ve encountered the code provided by Priyanka so I’m not sure how to fix it. :slight_smile:

@jcastro no problem.
Thank you for helping this much.

But still no luck
facing the same error
Syntax error: Missing operand after ‘Type’ operator.

1 Like

Hi @RachelN,

Can you enclose the Export Type with ?