For each row in datatable uses same values each loop

Hi All,

First of all I’m not an UIpath expert yet and got a lot of info from this forum which helped me to get where I am now; thanks all for that!

In short; I’m currently trying to copy data from an ms excel sheet(3 columns;462 rows (first row is headers)) into an ms access db. What i’ve done so far is to get UIpath to;

  1. read the excel sheet and output it into a datatable (Dt1)
  2. with click image activity’s go to access
  3. with click image activity’s open the filter function
  4. take the first value(row2) from column 1 from Dt1 and use it to filter in ms access
  5. use hotkeys to go to a column to the right
  6. take the first value(row2) from column 2 from Dt1 and enter it in this column in ms access
  7. use hotkeys to go to another column to the right
  8. take the first value(row2) from column 3 from Dt1 and enter it in in this column in ms access
  9. with click image activity’s clear the filter funtion

Steps 3 to 9 is currently in the activity; for each row in datatable. So my expectation was that after step 9 it would go back to step 3 and then take the values from row3 in Dt1.

The problem is that it after step 9 it goes back to step 3 but it uses the same values from row2 again.

I’m currently using these expressions in a type into activity to get the data from;
Column 1 = Dt1.Rows(0).Item(0).ToString
Column 2 = Dt1.Rows(0).Item(1).ToString
Column 3 = Dt1.Rows(0).Item(2).ToString

How do I get UIpath to take values from the next row when it loops back to step 3 in the second run and so on and so on?

Please tell me what I’m doing wrong here.
I’m using UIpath studio 2022.10.3

Thanks in advance!!!

Kind regards,

Amrish1989

Hi Amrish,

Welcome to the Forum!

Do not use ‘Dt1.Rows(0)’ in your assign activity. It will always refer 1 row of the table. You have to use ‘CurrentRow’ or ‘row’ variable from the ‘For each row’ activity. So your assign activity should be like below.

Column 1 = CurrentRow.Item(0).ToString

1 Like

Hi @Amrish1989 ,

I believe you would need to Loop the data present in Datatable in order to iteratively access the next row elements.

Have you tried using For Each Row in Datatable Activity ?

This would need to be changed to the below :

Column 1 = row.Item(0).ToString
Column 2 = row.Item(1).ToString
Column 3 = row.Item(2).ToString

You were using the first row and not the iterative row that is passed from For Each Row Activity.
image

1 Like

Hi @Saravanan_Samy and @supermanPunch ,

You both gave the proper solution!
I went for the solution of supermanPunch with the screenshot which was very clear and description of the expression per column.

If I understand correctly I should not have to put the row number because I want it to iterate to the next one and the activity ‘for each row in datatable’ is taking care it is iterating to the next row right? Same with the Dt1 that I should not use in the expression because the activity already says it is from Dt1 right?

Thank you both!

Kind regards,

Amrish1989

1 Like

Yes @Amrish1989, your understanding is correct.

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