How to copy or delete current row in loop?

Hello, I have the following question.

How can I copy the current row from datatable to another? ( have index from loop)

Or is there any other way to separate rows based on If condition?

Hi @Mikolaj_Zielinski

You cannot delete current row while looping through a datatable.

what you can do is put a condition and add that required rows to a new datatable or filter datatable for only required items.

You can copy the current datatable and loop through the copied datatable and delete from original datatable also

Regards
Roshan

If you iterate using a For Each loop, rather than a For Each Row loop, you can delete based on the row index. Just keep in mind that if you delete a row, you do not want to increment the row index, since the datatable will now have one less element in it.

Yes, I know.
that is why im also looking for way to copy it to another table

Hi @Mikolaj_Zielinski

create a new datatable (DT1) and clone your Original DT

DT1=DT.Clone

go for a For Each Row and loop through DT activity put a If condition for the data validation
on condition is true means use Add data row activity and add row to DT1 (in add data row activity there is a parameter for row)

After looping DT1 will have information which you requires

Regards
Roshan

Nb: Please mark as solution if you found this useful :slight_smile:

1 Like

Also Invoke Code and Select from DataTable (VB.NET DataTable Select Function - Dot Net Perls) can help.