Problem with clear datatable inside for each row

Hello

Is this a bug?

I have two datatables and I want to clear datatable 2 inside an “for each row in datatable” of datatable 1.
UiPath Studio seems to ignore the value of “datatable to be cleared” and clears both datatables.

Regards
Soren

What are you trying to do? There’s no reason to clear a datatable over and over like that. Aside from the strangeness of the error, what you’re doing makes no sense. What’s your goal?

Datatables are objects. So when you assign Datatable2 = Datatable1, you are just telling both the variables to point to the same object/datatable. To get two different datatables, use Copy() instead.

Datatable2 = Datatable1.Copy()

HI @bobzbobz

This error is occurring because you are looping through a datatable and clearing the same datatable

Why are trying to do this any specific reason ?

This is the thing happened there

  • looping the datatable
    • it will goes into first loop and clears the datatable
    • Goes to second loop and will throw this error because the datatable variable has been updated with no rows , while it see for next row it cant find anuthing the datatable so its saying the Collection(Datatable has been modified) was modified

Regards
Sudharsan

@bobzbobz

You need to assign

Datatable 2 = Datatable1.Clone

Regards
Sudharsan

@bobzbobz
Because of you assigning the Datatable 2 = Datatable1

Both the datatable will be get cleared

Regards
Sudharsan

HI @bobzbobz

To Avoid this error, You can clone the DT1

image

Regards
Gokul

Hello everyone

Thank you for your responses.
The shown image was just to demonstrate the error.

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