Insert Row Into Datatable Based On Array of Int

Greetings,

I’m having trouble trying to add a datarow into a datatable based on an array of integers as the index.

Here is a script I have been trying to get to work inside of an Assign activity:

For Each item In dtDataTestIndex
mrcPricing.Rows.InsertAt(mrcPricing.NewRow, item)

dtDataTestIndex is an Array of type Int32
mrcPricing is the datatable

Also, the Assign with the code in it looks like this:

Assign:

mrcPricing = For Each item In dtDataTestIndex mrcPricing.Rows.InsertAt(mrcPricing.NewRow, item)

I am getting the following error - “Expression Expected”

It looks like I am possibly missing setting the Column that I want this to be at? Can’t quite figure it out.

The other approach I have tried is:


dtInsert is a variable type String. (While I don’t necessarily need anything in this datarow I am trying to insert, I am trying a test string just for testing purposes with the add datarow activity.)

I am getting the following error: “Option strict on disallows late binding”

Really appreciate everyone’s help. I’m so close to completing a large suite of automations, and plan to share a step by step guide once I am complete.

Hi,

Output from Chat GPT(Try it out if the below doesnt work):

The error message “Expression Expected” is indicating that the syntax of the Assign activity is not correct. The For Each loop needs to be inside a separate Sequence activity. Also, you need to assign the modified mrcPricing datatable in each iteration of the loop.

Try the following:

  1. Drag a Sequence activity onto the designer panel
  2. Inside the Sequence activity, drag a For Each activity
  3. Set the dtDataTestIndex as the input of the For Each activity
  4. Inside the For Each activity, drag an Assign activity
  5. In the Assign activity, set the value to mrcPricing.Rows.InsertAt(mrcPricing.NewRow, item)
  6. Assign the value of mrcPricing to itself.

This should insert new rows into the mrcPricing datatable at the index specified by the dtDataTestIndex array.

The “Option strict on disallows late binding” error message occurs when you are trying to use late binding (when the data type of a variable is not explicitly declared) in a VB. NET program where Option Strict is set to On. This is a feature in VB. NET that requires all variables to have their data types explicitly declared, and can help prevent type-related errors. To fix this error, you can either set Option Strict to Off in your program (by adding the line “Option Strict Off” at the top of your code file), or you can explicitly declare the data type of the variable that is causing the error.

Thank you for your response, I love ChatGPT -

I tried what ChatGPT said, but I am getting the following error from the assign - “Expression does not produce a value”

@Sc100

In the add data row as per picture and the error the input you are providing and the target column datatype are different…

Ideally you would give an array input {value1} like this…this is for 1 column…add as many as you have columns with comma separation inside the curly braces…

Here dt.rows(item)(0) would give the valu of first column and the row number would be as per item value

Cheers

Thank you again for the responses.

I finally ended up doing:

Inside an Excel Scope

Would have preferred to do it in the datatable inside UiPath, but this will work for now. The datatable would have ultimately been written to an excel sheet, so I guess this method is fine.

If anyone knows how to do this, but with the datatable inside of UiPath, please do share!

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