LINQ query to update(replace)datatable in uipath
I have input data table as
Col1 Col2
ABC
123 ABC
I want to replace the empty value to “NA”
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:
(From r In dtData.AsEnumerable
let ra = r.ItemArray.Select(Function (x) x.ToString.Trim.Replace(" ","NA")).toArray()
Select 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.