Index out of bounds of the array: Add data row activity

Hello all,

I am trying to copy my data from one Excel file to another Excel file, with different order of headers in both, trying to copy my source file in order of destination one.
Everything is going quite okay before this Add Data Row activity. Attaching screenshot for reference. Thankyou!!

@Neha_Kumari1
there are different accesses by an index e.g. cheque(2) and we would suggest to analyze this on order to sort out the issue

*set a break point on add data row

  • debug
  • check the different accesses one by on in the watch / immediate panel
1 Like

@ppr Yes, it’s not reading the cell correctly. How to correct this
Likewise we used to do for reading cells without defining variables ones, as such row.Item(value). ToString
How to implement the same with variables

@Neha_Kumari1
a perfect analysis done by you :+1:
now check the dr variable content.
in case of dr is a datarow just keep in mind the column index starts with 0

same we do with cheque. lets check cheque content and then checking the access index

Arrays have a fixed length.

You have provided too many items to the array.

Is your array length 6?

@ppr Variables are running quite okay.
But I just noticed what is actually happening, check out the screenshot with balance one, it’s actually taking value as one digit at a time


it looks like balance is of datatype string
and you was using without any issues

may we ask you to focus the analysis on cheque and dr?

1 Like

Hi @josephatomwanzia

Sorry I didn’t get you. Could you pease come again
Length is actually varying for different cells in my data table

Arrays have a fixed length i.e if the array can only contain an already defined number of things. eg 5 names. If you try to assign more than 5 names, you get the error you have.

Why not use a read range activity to read the entire excel into a datatable?

Else, use a list other than an array.

1 Like

@ppr Similar with cheque and dr. Cheque is actually holding similar data for each further cell. And dr ought to be DR . I let my data type remain string in build data table.
So issue is with data type probably

keeo in mind: if we do have a string variable: strMyVar with value “TEST” we access the different characters by using the index e.g. strMyVar(2) will return “S”

We assume you want to store the entire string on the datatable

What was the motivation to use the access?

1 Like

@josephatomwanzia okay, let me try with list
Changing my data type in build data table to list of string should work, right?

Nope, just use a read range activity. It will read the excel as is even the headers. The CTR+K to create a datatable variable in the output section in properties

@ppr Yes, sure will keep in mind.
Yes the entire string. I actually had in my head it should work as similar to string.item(0).ToString

it looks to me that issue comes just from a saml confusion. just take a small break and then approach the implementation a little bit with distance to keep the overview:

a datatable has columns, columns has datatypes - eg. Col1 (String),Col2 (Int32),Col3 (String)
when adding a datarow we create the RowArray

  • position in the array maps to corresponding DataColumn (0-Col1, 1-Col2 …etc)
  • value is what we want to store

Eg. var1 = “ABC” | Datatype: String, var2 = 34 | Datatype: Int32, var3 = “EFG”

So the RowArray {var1, var2, var3} will add data to the datatable

|Col1|Col2|Col3|
|ABC|34|EFG|

1 Like

Yes, I got it
Thanks a lot☺️
@ppr for all your patience and guidance.

Thanks @josephatomwanzia :slightly_smiling_face:

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