How to iterate through datatables


Im using two for each loop activities, where in
First for each loop DTrow has values 1,2,3

And inside that I’m using another for each loop DT2 which has values 18,19,20

So when the bot iterates through first DT it takes first item : 1
And moves to DT 2 and takes : 18

And second iteration, it takes 19, but the first DT is : 1 only.

I want the bot to take the values simultaneously like:
From first DT if it is 1 and DT2 18, 2 and 19, 3 and 20 like this.
How do i do this?

Assumption: both datatable do have the same row count

We can do it by

For each row in Datatable Activity: row in dt1 - Index output: idx

  • Assign Activity: d1Value = row(ColumnNameOrIndex).toString
  • Assign Activity: d2Value = dt2.Rows(idx)(ColumnNameOrIndex).toString

we can use a LINQ
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum


You can use for each row in datatable on dt1

and use a variable for index property in for each row activity and use that index to get data from second table for same index like currentrow("Col").ToString gives data from table 1 which is dt1 and for dt2 use dt2.Row(varindex)("Col").ToString

Hope this helps


Hi @ppr

Can you write a workflow using 2 for each loops and share

with this input

we are confused by

as we saw the request, that 2 loops are to avoid.

Maybe you can elaborate more on this or present more the use case on which you are working on

  1. I have one datarow values are 1,2,3

  2. And another datatable2 values are 18,19,20

As we are already using for each loop for DT2 to iterate and enter the data on an application
While entering DT2 values , i want to take the Datarow values also and enter.

For ex: bot is iterating 18 using for each loop,
I want to enter 1 also from datarow.

After completion of first iteration.
Bot moves to next iteration and takes 19,
I want to enter 2 from Datarow and so on

And yes the count of the datatable for both will be same

When nesting 2 loops you will get the by you reported issue

1,18 - 1,19 - 1,20
2,18 - 2,19…

As it will loop over all dt2 rows and the iterate to next dt1 row

For the requested case we shared:

I don’t understand how to use this

along with:


I don’t understand ColumnNameOrIndex meaning


in the datatable you have columns right…index represents 0,1,2,3 for each column

and column name represents the name of the column in the datatable


A datatable has Data Rows and Data Columns
When accessing the data column value of a datarow we can use

  • the data column name


  • the data column index


ID Item
100 Apple
200 Mango

row(“Item”).toString will return Apple for the first Data row
row(1).toString will return Apple for the first Data row

You have used assign activity here for DT2 , how it is looping secondDT?

using the row index it is accessing the particular row directly.

Just implement it and explore it more while running / debugging it