Add data row activity with dynamic number of columns


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:


Please advise on how to calibrate cheers

check the columns in your data table. its required correct columns


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


Read the original data table from an Excel file
Read Range
Output: originalDataTable

Count the number of columns in the original data table
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


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!!


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


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.