Update specific column of a DataTable without using loop

I have to remove a symbol (if exists) from one specific column of a DataTable? Do we have any way to achieve the same without using any loop in UiPath ?

1 Like

Hey @sishiramishra

"Your_Datatable_name".Rows("rownumber").Item("columnName/columnNumber") = "your new value"

Regards…!!
Aksh

It will replace the value, I have to update.

Eg: All -ve symbols should be removed

Is is just the assign new value give by you to that particular Row and column, Rest regarding to replace “-” you have to perform your string manipulation like string.replace or Regex.

"Your_Datatable_name".Rows("rownumber").Item("columnName/columnNumber") = "your existing value".Replace("-","")

Regards…!!
Aksh

hi @aksh1yadav ,

how about if the row is empty then it will replace the value.

is it possible?

@aksh1yadav, I have kind of a similar requirement. I’m looking for a way to convert all values in a datatable column to uppercase without using a loop. Can we do this?

@Tharusha_Jayadeera

Try below expression.

          outputDT = inputDT.AsEnumerable().ToList().ForEach(Sub(row) row("ColumnName") = row("ColumnName").ToString.ToUpper).CopyToDataTable
1 Like

I tried to write this in an Assign activity but it gives an error saying “Expression does not produce a value”. Did I miss something?

@JoshLoops

Welcome to our UiPath community.

Can you show me screenshot of the expression you used here. So that I can check and help you.


see the screenshot of the compiler error. My intention is to write “Invalid” on all cells under the ‘Issue’ column of the datatable

This is what I wrote on the assign activity:
dt_InvoiceNames.AsEnumerable().ToList().ForEach(Sub(row) row(“Issue”) = “Invalid”).CopyToDataTable

Thanks

Hi,

Use the below code in invoke code activity

For Each row As DataRow In in_InputDataTable.Rows
row(“Issue”)=“Invalid”
Next

Thanks and Regards,
Sanjit Pal

2 Likes

Thanks for this. One of the simplest way to do it. I guess, I’ve been to skeptic about not using loops :sweat_smile:

1 Like

@lakshman, I got the same error “Expression does not produce a value ”.

@Sanjit_Pal, I think the solution proposed should work. But it’s again a for loop exactly similar to For Each Row activity in UiPath.

Thanks,
Tharusha

Hi @Tharusha_Jayadeera

Yes, the statement is also a for each row but it would not take as much time which is taken by the For Each Activity in uipath. It would take very minimal time

Thanks

1 Like

@JoshLoops

Sorry. I forgot to mention one point here.

You need to write expression in Invoke Code activity.

dt_InvoiceNames.AsEnumerable().ToList().ForEach(Sub(row) row(“Issue”) = “Invalid”)

Note: Create one argument for Invoke Code activity and mention properties as below.

Name - dt_InvoiceNames
Direction - In
Type - DataTable
Value - dt_InvoiceNames

@Tharusha_Jayadeera

Sorry. I forgot to mention one point here.

You need to write expression in Invoke Code activity.

InputDT.AsEnumerable().ToList().ForEach(Sub(row) row(“ColumnName”) = row("ColumnName").ToString.ToUpper)

Note: Create one argument for Invoke Code activity and mention properties as below.

Name - InputDT
Direction - In
Type - DataTable
Value - InputDT

2 Likes

@Sanjit_Pal, @lakshman Thank you very much!

2 Likes

You know that still loops, right? It’s impossible for any method to update a database without looping.