Modificar cada linha de um dataTable

Olá comunidade.
Preciso substituir cada linha de uma tabela, por exemplo.

Coluna X
123451
154321
134561

Por:

Coluna X
Y23451
Y54321
Y34561

Poderiam me ajudar?
Obrigada

let assume data is within a datatable:

For each row in Datatable Activity - row in YourDataTableVar

  • Assign Activity: row("Coluna X") = "Y" & row("Coluna X").toString.Trim
  • Assign Activity: row("Coluna X") = New String("Y" & row("Coluna X").toString.Trim.Skip(1).toArrray)

Hi @devrpa746,

The easiest way to do this is with a For Each loop.

For Each dr As DataRow In dt.Rows
dr(“Coluna X”) = “Y” + dr(“Coluna X”).ToString().Substring(1)
Next

You can also use a linq statement.

dt2.AsEnumerable.ToList.ForEach(sub(a) a.SetField(“Coluna X”, “Y” + a.Field(Of String)(“Coluna X”).ToString().Substring(1)))

The UiPath Studio example with activities is here: Modify DataTable.xaml (10.5 KB)

The VB.NET example is here: C# Online Compiler | .NET Fiddle

Thanks

@devrpa746
as seen we do have different approaches like for each, an option presented by @Kristopher . Also have a look here:

Obrigada! Obtive sucesso com os exemplos.

Também preciso escrever esses itens modificados em uma nova dataTable, ou simplesmente atualizar a que ja tenho. Poderia me ajudar nessa questão? Ficaria muito grata.

Hi @devrpa746,

In both examples, dt and dt2 were updated with the new values. You should be able to use the updated dt or dt2 in the rest of your process.

Thanks

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