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
ABC
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
dt.Rows(dt.Rows.IndexOf(row))(βCol2β)=βNAβ
@Rachel7
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()