Can we get values from datatable but with specific row index?

Can we get values from datatable but with specific row index?

example:
i have DT1 with 3 columns

DT1:
Column1, Column2, Column3
A, B, C
D, E, F
G, H, I

i have row index variable = 1

so, i want to get DT1’s row index 1 values:
Column1, Column2, Column3
D, E, F

Hi @wija

Use this:
row = DT1.Rows(rowIndex)

outputArray = dtInput(RowIndex).ItemArray

Output Array is of type System.Object()

@wija

  1. Assuming you already have a DataTable named “DT1” with the data you provided, create an integer variable named “rowIndex” and set its value to the desired row index you want to retrieve (in this case, 1).
  2. Use an “Assign” activity to get the specific row from the DataTable using the “DataTable.Rows” property. Create a variable named “selectedRow” of type DataRow, and use the following expression:
selectedRow = DT1.Rows(rowIndex)
  1. Now, you can access the values of the specific row using the column names. For example, to get the values of Column1, Column2, and Column3, you can create three string variables and use the following expressions:
column1Value As String = selectedRow("Column1").ToString
column2Value As String = selectedRow("Column2").ToString
column3Value As String = selectedRow("Column3").ToString

Now you have the values of the specific row from the DataTable stored in the variables column1Value, column2Value, and column3Value.

You can use the expression
col1Value=dt(rowIndex)(“ColName”).ToString
col2Value=dt(rowIndex)(“ColName”).ToString
col3Value=dt(rowIndex)(“ColName”).ToString

Hi thank you for your full explanation,
What if my DT1 don’t have header? Can we use the column index instead?

But i can’t try it right now, going to sleep first, then try tomorrow

1 Like

Yes you can use column index

I see, alright then.
Thank you for the response

@wija
Yes If you don’t have headers in excel then you can retrieve data through index like this:

selectedRow = DT1.Rows(rowIndex)
column1Value As String = selectedRow.ItemArray(0).ToString
column2Value As String = selectedRow.ItemArray(1).ToString
column3Value As String = selectedRow.ItemArray(2).ToString

1 Like

Ok this works, thank you

1 Like

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