LINQ query to update(replace)datatable in uipath

LINQ query to update(replace)datatable in uipath


Can you please share your condition and sample data @Rachel7

I have input data table as
Col1 Col2
123 ABC

I want to replace the empty value to “NA”

@Rachel7 should be technically possible, has done some statements very very close to this task

Great @ppr. Can you pls share it.

@Rachel7 Sure, but give me some time I have to rusch into several meetings in a few mins.

dt.Select(“[Col2] like ‘% %’”)
This will give you list of data rows then use for each then check if condition
row[Col2]=“” then take assign activity and give like this

this is maybe a too quick shot as it replace any space in any column to NA and returns a datatable.
But you can give a try

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

NEW VERSION, simplified - replace all cols with only String.Empty content:

(From d In dtData.AsEnumerable
Let ra =d.ItemArray.Select(Function (x) If(isNothing(x), Nothing, x.toString.Trim.Replace("","NA"))).toArray
Select r = dtCorrected.Rows.Add(ra)).CopyToDataTable()

Variation - Handles only String Datatype Columns and keeps other DataTypes

(From d In dtData.AsEnumerable()
Let ra =d.ItemArray.Select(Function (x, i) If(d.Table.Columns(i).DataType.Equals( GetType( String )), x.ToString().Replace(";",",") , x)).ToArray()
Select r = dtCorrected.Rows.Add(ra)).CopyToDataTable()

Use statement from above within an assign and assign it to an empty dataTable: dtCorredted

Before the assignment above create an empty datatable with the same structure as OriginDataTableVar by an assign: Statement - OriginDataTableVar.Clone
dtCorrected = OriginDataTableVar.Clone()


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.