Error thrown when Building DataTable


#1

Hi,

I get this error when I try to build my datatable:

Main has thrown an exception

Source: Add data row

Message: Input array is longer than the number of columns in this table.

Exception Type: ArgumentException

System.ArgumentException: Input array is longer than the number of columns in this table.
at System.Data.DataTable.NewRecordFromArray(Object[] value)
at System.Data.DataRowCollection.Add(Object[] values)
at UiPath.Core.Activities.AddDataRow.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Here’s the project i’m working on: Main.xaml (24.4 KB)

Any help will be appreciated!


#2

Hi,
Your data table column count and your add data row value count may be different…
Or
Create data table by using new datatable
Then by using add data column activity add required column
Then using add data row activity add row to datatable


#3

Hi @Bradley_Mckinnon,

I also met that error before when I create a new datatable and add new data row to it.
The reason of that error is the number of elements in input array is bigger than the number of columns in datatable. So I think you should write line those number to check that. They must be equal to work properly.

Regards,
Hoang Anh.


#4

How do I establish what my row/column count is?

Is it the ArrayRow here;

And here is whats present in the “ArrayRow” box:

{bnetOrderTable,“Order#”,bnetTimeStampTable,“Time Stamp”,bnetProductTitleTable,“Product Title”,bnetGameKeyTable,“Game Key”}


#5

Hi @Bradley_Mckinnon,

Your datatable has 4 columns, but your array contains more than 4 values.
So the problem is at your array of value.
It should be something like this: arrayrow = {“value1”,“value2”,“value3”,“value4”}.
Hope this help.

Regards,
Hoang Anh.


#6

Hi,

Thanks for prompt reply!

I have tried {“bnetOrderTable”,“bnetTimeStampTable”,“bnetProductTitleTable”,“bnetGameKeyTable”} in the ArraryRow Input box.

Still throwing an error:

Main has thrown an exception

Source: Add data row

Message: Input array is longer than the number of columns in this table.

Exception Type: ArgumentException

System.ArgumentException: Input array is longer than the number of columns in this table.
at System.Data.DataTable.NewRecordFromArray(Object[] value)
at System.Data.DataRowCollection.Add(Object[] values)
at UiPath.Core.Activities.AddDataRow.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Here’s the project i’m working on: Main.xaml (24.4 KB)


#7

Hi, @Bradley_Mckinnon
In your flow you are creating 4 add data column activity only. That mean only 4 column available in datatable(bnetinfo table)
But in add data row activity you are try to insert 8 column … in datatable
That’s showing error
Regards,


#8

Yes that was true shortly ago. But as @anhth15 mentioned of useing;

To which I then tried

Still throwing the same error.


#9

Can you check column count for that datatable
Using Yourdatatable.columns.count


#10

Sorry to be useless here. But how would I go about doing that?


#11

When you checking column count
you can identify how many columns in your datatable…
In case that value less the 4 you may make mistake in adding data column
By using that you can cross check your data row count also
By using that two you can solve your error k…


#12

Hi,

I did a assign for the column count and row count with a message box to report how many of each it has.

Both prompted “0”

So apparently my datatable has no structure at all?


#13

Hi @Bradley_Mckinnon,

I review your workflow and found out your problem at 4 “Add Data Column” activities.
You put wrong datatable into datatable input value of those activity.
Please change that field of all 4 activities to “bnetInfoTable” value and run again.
Hope this help.

Regards,
Hoang Anh.


#14

Hey,

Did what you suggested, now it’s giving this error;

Main has thrown an exception

Source: Add data row

Message: Type of value has a mismatch with column typeCouldn’t store in Order# Column. Expected type is DataTable.

Exception Type: ArgumentException

System.ArgumentException: Type of value has a mismatch with column typeCouldn’t store in Order# Column. Expected type is DataTable. —> System.ArgumentException: Type of value has a mismatch with column type
at System.Data.Common.ObjectStorage.Set(Int32 recordNo, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object value)
— End of inner exception stack trace —
at System.Data.DataColumn.set_Item(Int32 record, Object value)
at System.Data.DataTable.NewRecordFromArray(Object[] value)
at System.Data.DataRowCollection.Add(Object[] values)
at UiPath.Core.Activities.AddDataRow.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Thanks in advance!


#15

Hi @Bradley_Mckinnon,

Please change the typeargument in “Add Data Column” to string type.
Hope this help.

Regards,
Hoang Anh.


#16

Hi,

Success! Thanks @anhth15! Now it seems my variables are not actually presenting data in the csv as shown below;

uipath sheet


#17

Hi @Bradley_Mckinnon,

try this:
arrayrow = {variable1,variable2,variable3,variable4}.

these variables contain value which you want to put into datatable row.

Regards,
Hoang Anh.


#18

Hi,

I filled the “ArrayRow” with your suggested format useing:

{bnetOrderTable,bnetTimeStampTable,bnetProductTitleTable,bnetGameKeyTable}

How ever now the spreadsheet has no data input at all in the first row, as shown below:

ui2


#19

Hi @Bradley_Mckinnon,

Please write line those variables to make sure that they contain value.

Regards,
Hoang Anh.


#20

Hi,

Could you please provide an example of how I would achieve that?

Here’s the project i’m working on: Main.xaml (25.4 KB)