Convert List(of String) when using add data row activity and show object reference not set to instance

I’m doing a process that getting an excel file which the columns are not fixed every time.
In order to achieve my purpose with the process, I used List(of string) to fetch each column of rows. Then after formatting the data, I used Add Dara Row Activity wants to store in another new Excel file/Table.

And the problem is it showed up “Object reference not set to an instance…” when I convert my List(of string) to ArrayRow using ToArray().

Does anyone know why it cannot work?

Is ResultDT is initialised?
Make sure it is initialised before adding rows to it.

For example:

ResultDT = new DataTable

and then add rows to it.

Regards,
Karthik Byggari

1 Like

Hey @opas1216,

also make sure your List(of string ) is properly initialized.

Thank you everyone for kindly advices.

Before I only initialized the List(of string).

After added, right now both of List and ResultDT are initialized.
It still comes out the error, but the message changed.
“Add Data Row: Input array is longer than the number of columns in this table.”

I still cannot get the point that even it said input array is longer than the table, but the problem is I only know how long should I give to the table when I fetch the excel(It’s dynamic).
So i think I have no way to give a size in default to solve it. does my thought correct ?

Hey @opas1216,

Is there any pay you can convert your list value in the format as mentioned below:

{Value 1,Value 2,Value 3}

and then pass this inside the arrayrow.

Hi @opas1216,
According to me if you use the for each row and then use the list inside it for the purpose it may be useful.
For the iterable value we then keep it as row.itemArray Then it works.
Cheers:grinning:

Thanks for every suggestion and advises.

Finally, the work is done and come back here for leaving some conclusion for everyone further reference.

Follow the previous situation description, first has to format the data content from pdf to excel for further data fetching.

However, due to the data source was converted from PDF to Excel, the content didn’t group as a Data Table which means without Table name I can’t use “Get Table Range” activity to know the range of specific data content from the excel file(It also separated to several sheets), otherwise I can write back the formatted data to the right place(particular cell).

Hence, I decided to fetch the data from each cell of each row. Everytime I fetch a cell and store as a List(of string), consider of the content range might be dynamic in the future, to store and know how long does the Data Table is. After it deal with one row, it write List into a temperate DT.

The first point is to make sure to initiate the variables, not only List(I only did this before @KarthikByggari @amarasto mentioned, thank you so much, I appreciated it.) but also DT.

The second point is, I declare the DT at default without given specific columns since I don’t know the exact range, it’s the reason why it came out error “Add Data Row: Input array is longer than the number of columns in this table.”

Make sure no matter know how large the range is or not, it needs to “add Data Column” before using “Add Data Row”.
Thank you @Vashisht for advice, I did the same as you said at first, but it didn’t work probably because of w/o “add Data Column”.

Really thank you guys for helping me overcome this issue.

2 Likes