How to add data row into a Datatable

Hello,

I have created a Data table with the activity “Build Data table”
I have 7 columns, as following
columns : str_var | dbl_var1 | dbl_var2 | dbl_var3 | dbl_var4 | str_var | str_var

I collect information on the first step of my flowchart, which add data into the first row for the first five columns.
I used a “add data row” activity : I wrote in “ArrayRow”, the five variables I collected previously
{in_EAN, io_FTE, io_PV, io_PAE, io_PCI}

then i collect information that I need to add (at the same row) but to the 2 last columns.

How can I do that please ?

Thank you very much for helping me.

When adding a new row using the ArrayRow parameter, you need to make sure the number of items in the array matches the number of columns. For example, you can use blank strings for the column that you don’t have the data yet:

{in_EAN, io_FTE, io_PV, io_PAE, io_PCI, "", ""}

Now to update the row later, you need to refer to it by its index. If it is the last row you added, then you can use the last index. So using two assign activities you can do something like:

MyDT(MyDT.Rows.Count - 1)(5) = "new value" ' get the last row, sixth column
MyDT(MyDT.Rows.Count - 1)(6) = "new value" ' get the last row, seventh column

Hope that helps!

1 Like

Thank you @oddrationale for your answer
I did that but I have an error message saying that Cannot create L-value from given expression with property ‘set_Item’ because target object is Null. "
Do you see, by chance, what is the issue.
Thank you again

Which activity caused that error? Is it the Add Data Row? Or the Assign?

If you could post a screen shot that would help!

I have this error in the Assign Activity. I didn’t use the add data row activity but maybe I need to use both ?
Sorry, but i’m a rookie in UiPath.
And this is the screenshot of the error (it’s in French, i don’t know if it will help)

Ah, OK. Yes, make sure to add the row first. Then you can assign new values to the new row.

Yes sure, I added one Add Data row activity at the beginning and for the first row, I added the two value in quotes like you suggested me.
{in_EAN, io_FTE, io_PV, io_PAE, io_PCI, “”, “”}

Or do, I have then to add anothe activity add data row ?

What I want to do is to add values to the first row, where i have put already the five first data in this row. (I hope i’m clear).

My Mistake, I didnt write properly the name of my dt. I put the other one (coz I have two dt)
anyway it is working perfectly now

Thank you and sorry for this !

1 Like

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