Initialise a datatable and set default values in one variable

Hi, how can I initialise a datatable without using the build datatable activity and set the default value aswell as the column header values in one variable?

Like this:
DataTable Var = New System.Data.DataTable [Column name] {default value}

Etc…

I hope that makes sense? I need to initialise and set value in one go

Fine
to initialize a datatable in variable panel create a variable named dt and with type as System.Data.Datatable and default value as New System.Data.Datatable
and inside the studio use INVOKE METHOD like this

Cheers @rohangroombridge

Ok. Thank you. Is there a way to do it all in the variable without using activities?

but that would make the process too complex buddy
thats why build datatable activity where introduced
but still if we want to do so
i would recommend to do that only for few columns and rows
and to pass variables to those column created use assign activities like this Once after adding rows similar to that of column created with invoke method
dt.Rows(rowindex)(“yourcolumnname”) = “yourvalue”
or
dt.Rows(rowindex)(columnindex) = “yourvalue”

where both row index and column index starts from 0 for first row and first column

Cheers @rohangroombridge

3 Likes

Ok thank you. Is it possible though?

1 Like

yes buddy
but i would suggest you to use build datatable activity which is very simple and precise
Cheers @rohangroombridge

Ok thank you. Just so I know. What is the syntax to do it?

may i know for what the syntax you need @rohangroombridge

Initialise a datatable, set column names and default values.

I need it all in one sentence?

New System.Data.Datatable in default value in variable panel

then finally to add new row where variable1 is a datatable type
image

and to add value to that
dt.Rows(rowindex)(“yourcolumnname”) = “yourvalue”
or
dt.Rows(rowindex)(columnindex) = “yourvalue”

where both row index and column index starts from 0 for first row and first column

Cheers @rohangroombridge

1 Like

Ok but how do I do it without using the invoke activity? Can I just initialise and set the rest all in one line of code?

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.