Inserting data into the first row of datatable

Is there any way to insert value into the first row of an existing datatable?
For Example.

1 Red
2 Blue
3 Green

but i want to insert a new row on top of 1. So the End result is

99 Black
1 Red
2 Blue
3 Green

Hi @zhongyong11

Yes there is :slight_smile: It uses Invoke Method activity to do the job.

Please see attached project for reference:
InertNewRowAtTheTop.zip (10.5 KB)

Hi @zhongyong11

Yes, there indeed is.

You’ll have to do something like this: dtTable.Rows.InsertAt(drRow,intPos); where ‘drRow’ is the row you want to insert and ‘intPos’ is the position at which you want to enter the row.

NOTE: This code doesn’t return any value and just modifies the data table. Hence, use the activity “Invoke Code” and write this code inside it. I think @loginerror must have done the same thing, though I haven’t seen his code.

2 Likes

Hey @zhongyong11

you can find an existing old thread on forum too :slight_smile:

Regards…!!
AKsh

1 Like

Thanks for the example. is it possible to modify it so that it is able to insert into an existing datatable without using the build datatable activity?

Absolutely, I only did that so I can provide you with a working example. You can essentially only look at the Invoke Method activity and replace the variable names with yours :slight_smile:

1 Like

i tried it, i replaced your datatable variable name with my Datatable name, and deleted the build datatable activity, but i couldnt get any output afterwards.

Check if you have any data inside the datatable variable. The value of the datatable might be null. To check that, either debug your process or use output datatable to check what value you’re getting.

Edit: Could you upload your workflow here for people to see? We may be able to understand your issue better that way.

2 Likes

thanks guys. IT WORKS NOW :DDD THANKSSSSSS

2 Likes