Deleting rows of a datatable using starting index and ending index

Hi Team,

I have a datatable containing,
Invoice number, starting index, ending
abc,2,2
zyz,3,6

So, i want to delete the rows from starting index to ending index. How am i able to do it?

Hi @yash.choursia

Use Remove Data Row activity to remove rows

image

If you want to delete the columns use Remove Data Column activity

image

or use

image

I hope it helps!!

2 Likes

@yash.choursia

Can you breifly explain your query for better understanding

@yash.choursia

Read Range activity:
Input: Path to your Excel or CSV file
Output: dtInput (DataTable variable)

For Each Row activity:
TypeArgument: DataRow
DataTable: dtInput
Body:
If activity:
Condition: rowIndex >= row.Field(Of Integer)(“Starting index”) AndAlso rowIndex <= row.Field(Of Integer)(“Ending index”)
Then:
Remove Data Row activity:
DataTable: dtInput
DataRow: row

Hi @yash.choursia

Use remove data column activity to delete the starting index and ending index columns.

Or else:

use delete range activity to delete the particular range.

@yash.choursia

If you got the solution for your issue. Please mark it as solution to close the thread and others also helped.

Regards,

here 1-10 you have shown, UiPath is taking it as 9, but i want to delete all rows from 1-10. using linq(recommended)

To delete rows between a index you can use the below linq:-

In Assign Activity:- dtOutput.Select().Skip(startIndex).Take(endIndex - startIndex + 1).ToArray()
In InvokeCode:-

For Each rowToDelete As DataRow In rowsToDelete
    dataTable.Rows.Remove(rowToDelete)

Next
Note:- startIndex and endIndex is a variable that can be initialized based on your need

Hi @yash.choursia

If you want to delete all the rows in the datatable. You can use the Clear datatable activity.
It clear all the rows data in the datatable, the columns will be remain and we can use the datatable for further use.
image

Hope it helps!!

@yash.choursia

Try this

listDt and rowToDelete must be same, right?

Hi @yash.choursia

You can remove the rows in data table as

I hope it helps!!

Yes, it should be same.
The below are arguments for the for activity

1 Like

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