HI Team,
I want to delete the current entire row in for each loop which I am unable to do with remove data row activity.
From the above once the first row looped it should be deleted at the end .
HI Team,
I want to delete the current entire row in for each loop which I am unable to do with remove data row activity.
From the above once the first row looped it should be deleted at the end .
Do you want to delete all rows or any specific rows with specific conditions?
Regards,
Firoz
Hi @karthik_kulkarni1 ,
Do you want to remove each row one by one after it is processed ? Or Do you only want to remove the First row ?
Maybe you could tell us more about the process by also letting us know what is the End Output expected for the Input Provided.
In a loop you cannot delete while looping on datatable directly
Create a counter and initialize with 0
for that use a for loop on Enumerable.Range(0,dt.RowCount).ToArray …this will create a loop for rowcount number of times
Inside loop if you want to delete based on condition then use a if condition and use delete row with rowindex as counter
And if deleted then do not increment the counter …else increment the counter using counter = counter + 1
cheers
First step reading a data table
second for each row in the data table
…all my conditions
at the end inside for loop I need to delete the first row.
Example after firstIteration
Input:
Output:
For this case, you wouldn’t need to perform the deletion of the row inside the For Each Row. You can use the Remove Data Row
Activity outside the For Each row
Activity.
Hi @karthik_kulkarni1
You can use like this outside after the for each row
Here dt_temp is datatable vairable.
Regards,
Firoz
If you want to delete each first row after each iteration
Then use for loop on Enumerable.Range(0,dt.RowCount).ToArray
And inside the for loop use remove data row with rowindex as 0
Then at end of each iteration each row is deleted
Cheers
Here I need to delete row by row in for each loop.
If I put Removedatarow outside for loop it work for only onerow but it should delete all the rows
So in each iteration at the end, you want to delete the first row
example
1st row is iterating
so at the end, you want to delete 1st row at the end of the iteration?
exactly @FIROZ_RANGREZ
You can place the remove data row like this
@karthik_kulkarni1
please review this
Agreed to above mentions. When deleting a datarow within a loop then we will ge a sequence was modified exception
when outside the / done with the loop we can delete the row as mentioned above:
or using rowindex 0 when first row is to delete
Another technique is to delete rows based on evaluations is to retrieve the different affected rowindexes (which rows are to delete), order the series descending and then delete the row by iterating over the descending ordered rowindex list using e.g. Remove Datarow activity
like this @karthik_kulkarni1
(if you want to query value in this loop, simply do
dt.rows(currentItem)("columnName").toString
Sequence1.xaml (8.0 KB)
you cannot simply use for each row in datatable activity and use remove datarow inside, because you cant modify the datatable while its looping
Hi @karthik_kulkarni1 ,
you can refer to @jack.chan solution,
my solution will give you an error because we cannot delete the row of the data table that we are directly looping using for each data row.
Please try this as said…inside for each datatable you cannot delete…so use a for loop
Cheers