LINQ query to replace column datatable in uipath

Hi everyone

I know my question is similar to this LINQ query to update(replace)datatable in uipath , but I need to do it only for one column not for whole datatable, I would replace “-” with " ", like this:

How can i do that?
Thanks in advance

@salvatore.quimi Why does the value change from 466 to 6646 ?

no it has not changed it is me i have modified manually, but instead do you to know how to use linq query to replace value? thanks in advanced

similar to the reference topic, you can try a replacement over all columns with:

(From r In dtData.AsEnumerable
Select ia = r.ItemArray.toList
Select ic = ia.ConvertAll(Function (e) e.ToString.Trim.Replace("-","")).toArray()
Select dtCorrected.Rows.Add(ic)).CopyToDataTable()

Hi @ppr yes, thanks but i need only to one column

when it is not harming the other values so it will not matter. Otherwise LINQ is less helping as solving in the 1 Col scenario. It is more straightforward to do it with a for each row and directly within an assign

Yes I’m using for each row and assign but if I had to do it for multiple columns but not all DataTable, do you always suggest me for each row and assign or is it possible with Linq query?

Thank you

as long you can do it with for each (readable, maintainable by any skill level, tolerable execution time…) start to do it with for each.

1 Like

So this will have to go into a new dt? is not possible to overwrite the existing values in the column?

Feel free to open a seperate Topic on it or reach me by message.

The most important factor on an implementation is maintainability and that there is a chance to track the processing.

Using a Linq in an Assign statement is forcing that the LINQ Statement is returning something (L-Value assignment). Updating a column will fail:

  1. ) dt.AsEnumerable.Where(Function ( r ) r.Field(Of Int32)(0) < 2).Select( <- return is needed
  2. ) other tricks e.g. return someting and do col update will not validate
  3. ) dt.AsEnumerable.Where(Function ( r )r.Field(Of Int32)(0) < 2).toList.ForEach(Function ® r.SetField( <- return is needed, SetField is a SUB(routine, no return)

Thats why the trick with adding new rows to empty datatable works as DataTable.Rows.Add… is returning the datarow (a later copyToDataTable we wouldn’t need, we just take it for getting something returned)

Shifting to e.g. Invoke Code would allow to do things without mandatory return needs. But then we put it like in a blackbox. This is against/stressing the principle from above.

Thats why updating within a for each, other well balanced LINQ/ForEach/essential Activities combination are prefered.

For sure with other priorities / principles technically it can be done different e.g. as described in 3. ). it is up to everyones personal decission.