Hi, how can we remove records from the data table?
Like, I have SNo. in a data table, I am processing each SNo. and then remove from the Data Table one by one. Simple printing SNo. one and remove the printed one from Data Table, again printing the 2nd number then remove from the Data Table like wise. Please suggest. @Palaniyappan@KarthikByggari
No bro, this is not the requirement, my process is designed in such a way, If I am processing a ID I have to remove that ID from the Data Table. Like Once process then remove from the Data Table. I don’t want to increase the data table size. So that in every iteration I can see the Data Table side, If there is 0 records in Data Table then finish the process.
Let me tell you the reason why we won’t be able to delete the records while iterating through datatable
In For each row the whole Datarow array value is sent as input and while iterating if we are trying to delete the record then it will not allow deleting and throws error
Similarly as you want to finish once all the records are done so does the same in for each row with all data iterated and then it comes out after all the records are processed
And immediately we can clear the datatable with CLEAR DATATABLE ACTIVITY
both does the same and the one you suggested will Throw error when we try to delete or remove records when it is iterated through for each row
But the second one won’t as all the records are processed and we are clearing only after looking on all records in the datatable
Cheers @balkishan
understand, but this method will not help me. here my scenario is different. so it can resolve only when we remove the processed records only one by one.
Ex. I have 10 records in a DT, I have to check multiple page to check those 10 records. so this DT loop is inside the main loop. So my first loop will iterate until it find all the records from the DT.
For that, use following code in assign at the end of loop, i mean For Each Row,
DT = DT.AsEnumerable.skip(1).CopyToDataTable
—> this will remove 1st row one by one with iterations. Only at the last iteration datatable will be empty, so it’ll give you an exception and that could be handled using try catch.
I’m attaching here, 1 sample workflow for your better understanding. —> Main.xaml (10.7 KB)
Check data of build data table activity and run it.
Hi Samir,
I have written contains check and int_index is populating correct and copied to data table but I want to read Index Ex: 9 from 50 and want to skip remaining records to be copied.
I have checkpoint in file with String “End” at 50th line of my file . as per below line it is giving all lines from Index 9 to end of the excel. please let me know how can we copy from 9 to 50 in my example.
dtInput.AsEnumerable().Skip(int_index).CopyToDatatable(). Please suggest and I am new to UI Path.