Removing multiple rows from data table

Hi,

I want to remove multiple rows from a data table. For example lets say I am having datatable DT1 and I have to remove 2nd, 4th and 5th row from it. Could anyone please advise what’s the best way to achieve same.

Thanks,
Kapil

Hi Kapil,

Are you checking for any condition in the row value and then removing the rows or directly you will decide on from which index the row should be deleted?

If its based on condition, (variables are specified in bold)

  • use select query to apply the condition on datatable, DT1 and get the output as array of datarow, arDataRow
  • Loop through arDataRow and check index of each row in DT1,
    index = DT1.Rows.indexOf(row)
  • To remove the row, Use Remove data row activity and in properties specify Datatable as DT1, RowIndex as index
  • Continue the loop until all array items are processed from arDataRow

If you don’t need to apply and conditions and just want to remove from the known indexes,
Use Remove data row activity and in properties specify Datatable as DT1, RowIndex as index from your list.

Hope this helps!

2 Likes

For Row indexes actually this does not work in my observance, because as you delete the rows, each row index in target DataTable lags/shifts upwards. Index 3 is no longer the Index 3 in the DataTable, if you remove one row.

you have to reverse the loop and start deleting the last item first.

2 Likes

hi @Kapil

please find the attachement and book1.xlsx is my excel attach yours…

BlankProcess1.zip (9.9 KB)

@Kapil

If there is only three rows use

Remove DataRow Activity
image