How to initialize a DataTable with Values as an argument?

How can I initialize a DataTable with default-values for testing/debug as an in_argument in a workflow?
It must be something similar to:
New DataTable from { {“row1col1”, “r1c2”}, { “r2c1”, “r2c2” } }
How exactly should be the syntax please?

// please understand the question and don’t recommend activities as “Build DataTable” (as in other topics), cause when the workflow is invoked, the in_datatable is already initialized. The need is just for quick testing and debug the xaml alone (independent of the rest of project)

out of the box, there is no DataTable init statement, which populates also the values, as the data table needs a defined column structure

However, have a look at this JSON trick

1 Like

Try this
New DataTable From {{"Column1", "Column2"}, {"row1col1", "r1c2"}, {"r2c1", "r2c2"}}

Regards,
Arivu

error BC36718: Cannot initialize the type ‘DataTable’ with a collection initializer because it is not a collection type :frowning:

we got this error as it is not supported, due to also mentioned:

thx, it looks interesting and could be a solution

  1. JArray is not declared. What have I import for it?
  2. please write the syntax as a text, instead of picture, so we can copy it to test it :slight_smile:

Hi @Chris.ro ,
NO LUCK

There is no single line code to create a datatable with default values.

You have to use build datatable/invoke code/ using multiple assign activity to achive.
or you can go with @ppr suggestion

Regards,
Arivu

thx arivu, I like also the ppr’ suggestion.
What do I need to use his “JArray”?

btw: the syntax could be also on more lines. Do you know how init on more lines?

JArray.Parse("[{""col1"":""val1""},{""col1"":""val2""},{""col1"":""val2""}]").ToObject(Of DataTable)
2 Likes

when lines are rows, then it is already done:
grafik
as we already can proof

When structure is about more columns, similiar we can use the JSON Trick:
grafik

JArray.Parse("[{""col1"":""valA1"",""col2"":""valB1""},{""col1"":""valA2"",""col2"":""valB2""}]").ToObject(Of DataTable)
3 Likes

solved!
many thanks @ppr

1 Like

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