How to use get row item with for each

datatable
activities

#1

How can I get single row item from one single row from a data table.


Citrix automation - Find and click an element in Citrix app based on row value from local excel app
#2

There are a couple ways.

You can use “Get Item” activity and set up its parameters correclty.
Most don’t use that method however and instead use “.Item()” with the datarow.

So in order to get the datarow you can have this in a ForEach or hardcode the row with the datatable variable.

For example,
datatableVariable.Rows(0).Item(0).ToString
that will return the first column of the first row. You can also replace .Item(0) with .Item(“columnname”)

If you have it in a loop, then here is an example of that:
ForEach row In datatableVariable
MessageBox row.Item(0).ToString
Since row is a datarow within the datatable that works and is similar but you can go through each row.

Hope this helps.

Thanks.


#3

Assign a DataRow dr=dt.Rows(0)
use for each
for each item in dr.ItemArray
WriteLine(item(0).tostring)


#4

Thanks ClaytonM!


#5

Thanks Bikash


#6

Thanks ClaytonM, it worked! :+1:


#7

Hi Clayton,

Iam having an issue.Iam using for each control flow to read the n number of rows from a data table like below.

item = dt.rows

Here is the challenge,I always I need to read only n-1 rows.How to write the code.

Thanks,
Shiva.


#8

Hi Clayton,

Iam having an issue.Iam using for each control flow to read the n number of rows from a data table like below.

item = dt.rows

Here is the challenge,I always I need to read only n-1 rows.How to write the code.

Thanks,
Shiva.


#9

Hi.

If I understand you correctly, you want to loop through a data table but skip the last item?
If that is true, then use a generic For Each (not the “For Each row”); make sure to choose the UiPath.Core one and not the UiPath.Framework one.

So to skip the last item you can utilize .Skip or .Take by using the table like an enumerable.
Here’s how:

For Each row In dt.AsEnumerable.Take(dt.Rows.Count-1).ToArray // use Data Row as the TypeArgument

That will loop each row except the last one but keep all rows of the table there.

I hope that helps.

Regards.


#10

will try clayton.


#11

Thanks Clayton,It got worked