Add data row activity with dynamic number of columns

Hello,

I have a add data row activity. The number of columns in my data table are dynamic. When I run my activity I get this error:

image

Please advise on how to calibrate cheers

@E.T.S
check the columns in your data table. its required correct columns

Hello,

Thanks for your reply!

Is there a way of counting the number of columns in my data table then adding that many columns in my new data table

Cheers

@E.T.S
Read the original data table from an Excel file
Read Range
Output: originalDataTable

Count the number of columns in the original data table
Assign
columnCount = originalDataTable.Columns.Count

Create a new data table with an initial column
Build Data Table
Output: newDataTable
(Configure with one initial column)

Loop through the column count to add columns to the new data table
For Each
Values = Enumerable.Range(0, columnCount)
TypeArgument = System.Int32
currentIndex = item

Add Data Column
DataTable = newDataTable
ColumnName = String.Format(“Column{0}”, item) // or any naming pattern

Thank you for your reply!

I am unsure how to do the following onwards: Loop through the column count to add columns to the new data table

Please would you be able to explain

Cheers

Hi @E.T.S

When you are giving the values in the Array row field in add data row activity, the number of values has to be equals to the Number of columns you have in the datatable.

Make sure to match the Number of columns to adding the values in add data row activity.

Hope it helps!!

@E.T.S

if you are only trying to add blank then just use {} in itemarray

cheers

That isn’t possible. A datatable has a set number of columns. If it has 8 columns you can’t use Add Data Row to add 9 values. You need to create your datatable with all the possible columns.