Append ' in to all row and column of datatable

I have a datatable name dt.in that datatable i have all type of value example: date,datetime,string,number etc.

I want to append ’ for all the rowvalue and column. How tp do that in UiPath.

To append a single quote to all the row values and columns in a datatable, you can use the following steps in UiPath:

  1. Use a For Each Row activity to loop through each row in the datatable.
  2. Inside the For Each Row activity, use a For Each activity to loop through each column in the row.
  3. Inside the For Each activity, use an Assign activity to append a single quote to the value of the current cell. You can do this by using the following expression: row(column.ColumnName) = “'” + row(column.ColumnName).ToString + “'”

This code is not working for the column where vale is datetime or number .i need to handle everyting

  1. Use a For Each Row activity to loop through each row in the datatable.
  2. Inside the For Each Row activity, use a For Each activity to loop through each column in the row.
  3. Inside the For Each activity, use an If activity to check if the value of the current cell is not a string. You can do this by using the following expression: Not TypeOf row(column.ColumnName) Is GetType(String).
  4. Inside the If activity, use an Assign activity to append a single quote to the value of the current cell. You can do this by using the following expression: row(column.ColumnName) = “'” + row(column.ColumnName).ToString + “'”
    This will append a single quote to all the row values and columns in the datatable when the values are not strings. I hope this helps!

Not working, it is skiping the value where i have date or number. But i want to append ’ in all the row and column irrespective of value and type

Hi @Pinky_AG ,

Please find the attached xaml file for the solution. Still any doubts refer below mentioned video link.

syntax : -DT.AsEnumerable().Select(function(r)DT.Clone.LoadDataRow({r(0),“,” & r(1).ToString,“'” & r(2).ToString},false)).CopyToDataTable()
Append ’ in to all row and column of datatable Solution-No-8.xaml (9.4 KB)

Link:- https://youtu.be/eibCW0O6cs0 (Note: This video will popout on 1-Jan-2024, at 5:00PM onwards)

Regards,
Pavan Kumar/Techystack

It is still the same …getting following error:

Assign: String was not recognized as a valid DateTime.Couldnt store <'12/01/2023 00:00:00> in value Fate Column. Expected tupe is DateTime

Hi @Pinky_AG

For Each row in dt (TypeArgument: DataRow)
For Each column in dt.Columns (TypeArgument: DataColumn)
Assign row(column) = “'” + row(column).ToString
Next column
Next row

Already tested this code…getting same error

I have a vb code which is working like magic but looking for something simpler…

The vb code which work is:

Dim modifiedDt As DataTable = New DataTable()

For Each col As DataColumn In dt.Columns
modifiedDt.Columns.Add(col.ColumnName, GetType(String))
Next

For Each row As DataRow In dt.Rows
Dim newRow As DataRow = modifiedDt.NewRow()
For Each col As DataColumn In dt.Columns
If row(col) IsNot DBNull.Value Then
Dim cellValue As String = If(TypeOf row(col) Is DateTime, DirectCast(row(col), DateTime).ToString(), row(col).ToString())
newRow(col.ColumnName) = “'” & cellValue
End If
Next
modifiedDt.Rows.Add(newRow)
Next

dt = modifiedDt

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