Error thrown when Building DataTable

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!

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

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.

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”}

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.

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)

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,

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

To which I then tried

Still throwing the same error.

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

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

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…

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?

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.

1 Like

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!

Hi @Bradley_Mckinnon,

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

Regards,
Hoang Anh.

1 Like

Hi,

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

uipath sheet

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.

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

Hi @Bradley_Mckinnon,

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

Regards,
Hoang Anh.

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)