How to use get row item with for each

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

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.

12 Likes

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

Thanks ClaytonM!

Thanks Bikash

Thanks ClaytonM, it worked! :+1:

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.

1 Like

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.

1 Like

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.

1 Like

will try clayton.

1 Like

Thanks Clayton,It got worked

Thanks very much. It worked for me

Hi Guys,

Here is a detailed guide on reading Values From DataTable
# How To Read Values From DataTable(Excel) – In UiPath

Regards,

1 Like

Hey @ClaytonM I’ve read your comments and very helpful

Would you mind to help me on my query little bit similar to this?

Thanks