Adding a row to a data table at a specified index

datatable
activities

#1

For example,
We have a data table which contains extracted structured data from the web and I want to add a row to it (like a header) and then write the entire dataTable to an excel.

How can we add a row to the data table at the N-th index? I can see that Add Data Row activity adds at the very end of the data table. But in this case I need the row to be added at the very beginning.


#2

Hi @prajeeth1992,
You can use DataTable.Rows.InsertAt method.

Something like this:

DataRow dr = callsTable.NewRow(); //Create New Row
dr[“Call”] = “Legs”; // Set Column Value
callsTable.Rows.InsertAt(dr, 11); // InsertAt specified position

Check whether you are able to.
Regards,
Jiban


#3

Hi,

I want to use DataTable.Rows.InsertAt method but i don’t know how.

Can you give an example of how to do this in UiPath Studio?

Should I use Inovke Method Activity?

Thanks!


#4

Hey @danielcraciun

Yes…!!

Here you will find an example for you :slight_smile:

Regards…!!
Aksh


#5

Thank you! It works. I didn’t know exactly how to write method name.


#6

I want to add values to all column in the dt without specifying the col_name. Can you please let me know the code adjustment for that.


#7

bouncer…