Extract datarow values

Hi All,

I have a datarow passed as an argument from another workflow. I want to display all the values in the Datarow. How can I achieve that? I tried for each loop but I get the below error

Please help

1 Like

Hi there,

Inside the body, to see the values you can put:

  • Write line activity: item(“The name of the field you wanna print”).toString

For example, imagine you have a DT with next columns, Col1: Age ; Col2: Name ; Col3: Description

So, eg: item(“Name”).ToString will get the name of each row of the DT

Bests,
Pablo

It appears that your in_DataRowtoProcess variable is a DataRow. I am going to assume that is the case in my text below.

There are a couple of approaches to it: either get the column names and use those, or go by index:

  1. (slightly more complex) Use a For Each but go through yourDataTable.Columns and inside use in_DataRowtoProcess(item.ColumnName).
    Note, you will need to set the For each Type argument to System.Data.DataColumn for this to not whine about types :grin:

Pseudo-code would look like…

DataTable yourDataTable

DataRow in_DataRowtoProcess = row from yourDataTable

foreach (DataColumn column in yourDataTable)

print in_DataRowtoProcess(column.ColumnName)

  1. (slightly easier, but you’ll be working by column index) Use any sort of loop action that makes you comfortable; I’ll use a while loop; you’ll also need a counter.
    It is very simple: while counter < yourDataTable.Columns.Count (counter’s initial value should be 0 and dt.Columns.Count returns the total number of columns in your table).
    Inside the while, you will need to increase the counter (as the last step) and perform any action on the row as follows in_DataRowtoProcess(counter)

Pseudo-code would look like…

DataTable yourDataTable

DataRow in_DataRowtoProcess = row from yourDataTable

int counter = 0
while (counter < yourDataTable.Columns.Count)

print in_DataRowtoProcess(counter)
counter = counter + 1

Hope this helps.

1 Like

Hi… I tried this already, but it din’t work because, the datarow is passed from another workflow so the column name is unknown.

Hi @Pablo_Sanchez and @ANSI thank you for your response.

I found a way to resolve it. I passed the values as an array of strings and extracted through index :slight_smile:

1 Like

Glad it worked for you, but the DataRow being from another flow should have no effect on it’s column names.

1 Like