Question about accessing DataTable

A developer wants to print the value of the column “ID” of the first row from a data table variable “DT” using a Log Message activity. What value should the field Message from the Log Message activity have?

DT.Rows(0).Item(“ID”)
DT.Columns(0).ID
DT.Rows(0).Item(“ID”).ToString
DT.Columns(0)(“ID”).ToString
DT.Rows(0).ID

dtTable.rows(0)(“ID”).ToString

OR

dtTable.rows(0).Item(“ID”).ToString

@nevesisabela963

This is what works

.ToString to be added because log message needs a string

Cheers

Hey @nevesisabela963
the correct expression is DT.Rows(0).Item("ID").ToString

That’s what I thought, but the exam said it’s incorrect. Frustrating.

@nevesisabela963

Sometimes few of the things might be wrong as well..you can report it

Mostly it would have routed to option 1

Cheers

1 Like

Hi @nevesisabela963

Answer is DT.Rows(0).Item("ID").ToString because it correctly accesses the first row and retrieves the value from the “ID” column as a string, which is required by the Log Message activity. Other options use incorrect syntax or reference non-existent properties.

You can report because some answers are incorrect.

Happy Automation with UiPath

1 Like

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