Can't retrieve DataRow column names

Hi people,

I am using DataRow as TransactionItem to process some data inside an REF.
The number of columns may vary, in the sense that there may be 2 or more columns with names like this: TimePeriod 1, Timeperiod 2,…, Timeperiod X.

In short, i needto get the “X” and my thought process was to loop through the column names using an index and find out what “X” is.

In a datatable i could do this using a For Each column in DataTable, and use column.ColumnName, like so:
image

Is there a way to do this, assuming i have to do it on the DataRow? The column name info is there, i just need to get to it :slight_smile:

Thank you!
Serban

If it is always incremental column names as you say, “TimePeriod 1”, “TimePeriod 2” etc, why not just count the number of columns?

var = datatable.columns.count.tostring

then the column name can be assumed to be "TimePeriod " + var

@Serban

List_columnnames = dt.columns.columnnanes.tolist

This will give you a list containing column names.

Using index will be of second priority. Try using column header names to fetch data in case of dynamic datatable.

@ronanpeter @Ragu9060

Thank you both for your responses! They are valid and super useful insofar as we are talking about columns in a DataTable.

However, my question is reffering to the case where, for example, in a workflow file we have an In argument of type DataRow (let’s call it “OneRow”). There is no DataTable in this workflow.

So, to rephrase the question, is it possible to retrieve the column names for a variable or argument of type DataRow, assuming there is no DataTable involved?
Hope that is clearer. Thank you!

Hi @Serban ,

You can get the column names from DataRow by using (datarow).Table.Columns and this will return “DataColumnCollection”.

You have loop the DataColumnCollection object. For Each (DataColumn).ColumnName to get the column name.

Regards,
Sasikumar

4 Likes

Thank you, it works!!

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