Assigning data table element to a string array element

Back like I never left!

Now I’m attempting to grab an item (string) from a data table and assign it to a string array.

sampleStringArray(counter - 1) = sampleDT.Columns(ColumnName " + counter.ToString).ToString

I tried this in an assign activity but once it got to it it throws this error message

Screenshot%20(7)

The text I’m trying to grab is in a column hence the syntax I’m using. counter is just a counter I’m using to avoid any broken array (not for the reason you think so don’t ask on that) and to identify the index of the array I’m trying to pass this text on to.

Does anyone know how I could combat this? I believe I have the correct references of the object as UiPath didn’t give me a warning but I’m obviously missing something. Any help would be appreciated

Hi @Kriptiko,
Wouldn’t this be a problem?
image

Fine
Usually to add a value to array or any collections use ADD TO COLLECTION activity
where in collection property mention the array name
in item property mention the value you want to pass
–as we want to pass the value from a datatable, mention like this buddy
sampleDT.Rows(rowindex)(columnindex).ToString
both row index and column index starts from 0
we can use counter.ToString if we want
in Typeargument mention the type that array actually holds
Cheers @Kriptiko

My mistake, the assign activity in my code has ColumnName in quotations. I guess I missed the first one in this post. The reason for this is because there are columns that all start with the same name, but are different in that they have a number following them. That number in this instance is the counter I have set up. i’m trying to append the counter to the columnname string.

I tried this, but when I input the string array into the collection property it returns that I can’t convert the type string to collection(Of String).

Screenshot%20(8)

In the collection field I referenced the array and the index of where I want the item to go.

Collection
sampleStringArray(Counter - 1)
Item
sampleDT.Columns("ColumnName " + counter.ToString).ToString

The way I’m referencing the sampleDT item isn’t giving me any trouble which is why I didn’t change it. I only need the column with that specific name as the entire process is contained within a for each row activity.

No buddy in collection just mention the collection name, no index
like this sampleStringArray
and in item mention as
sampleDT.Rows(rowindex)(columnindex).ToString
the reason is this term sampleDT.Columns("ColumnName " + counter.ToString).ToString which will actually give us like this system.Data.Datatable.Columns and not the values buddy
Cheers @Kriptiko

1 Like