How to get the row index through selecting another datatable?

datatable
studio

#1

Hi everyone,
I want to add two data column to a datatable from another one like this.
sample_datatable

My aproach is here.
Step1. Use “For each row” activity with dt2 and get dt2.row(0) and dt2.row(1).
Step2. Select dt1 and get row index.
Step3. Use “Add data column” activity and add dt1.row(2) and dt1.row(3).
Step4. Assign dt2.row(0) to dt1.row(2) or (3). (this step will also use the same method)

I have no idea of Step2 method.

Best regards.


#2

hi @MarikoUsui

Check the below post

Thanks
Ashwin S


#3

Hi @MarikoUsui,
I have created the sample with ur datasource. Below I have attached the files.

File : get the row index through selecting another datatable.zip (21.5 KB)

image

Regards
Balamurugan


#4

Hey @MarikoUsui

You can get Row index from datatable inside Loop like below :slight_smile:

foreach(DataRow row in yourdatatable.Rows)
{
Int value_row_index =yourdatatable.Rows.Indexof(row)
//Writeline value_row_index.ToString()
}

Regards…!!
Aksh


#5

Hello @aksh1yadav,
just correctness
That gives an error, we have to use only like,
foreach(DataRow row in yourdatatable) {
}

Thanks,
Pankaj


#6

Hey @Pankaj.Patil

What error?

Mate for your clarification This is for Generic For each where you have to use System.Data.Datarow As an argument and in For each value you have to use Datatable.Rows :slight_smile:

Since i used it in C# so wrote like that.

Even if you will use For Each Row Activity from Uipath , yourdatatable.Rows.Indexof(row) this will be same :slight_smile: So you do not have to worry about for each construct i have mentioned above :slight_smile:

Make sense? @Pankaj.Patil

Regards…!!
Aksh


#7

Hello @aksh1yadav,

I was talking about For Each Row activity, you were only For Each.
That was confusion between us.

Thanks,
Pankaj


#8

I know that is why explained :slight_smile: mate

Regards…!!
Aksh


#9

@Pankaj.Patil @aksh1yadav
Thank you for your answer.I could resolve the probrem.


#10

I use the same way but it gave me error as For each row : Object reference not set to an instance of an object.

How can I put the index in my write cell, cell field? :frowning:


#11

Could you share your workflow file?


#12

Hi @MarikoUsui,

Thanks, attached the workflow.

ForTesting.xaml (8.5 KB)


#13

The usage of Rows.Indexof (row) is correct, but some errors has occurred elsewhere.

  1. Please add “dt” to the output field of the Read range activity.
    2 .and change the cell field of the Write cell activity from “B” +index.ToString to “B” +(index+1).ToString.
    try it.

#14

Yes I got it. We have 2 plus two. Thanks @MarikoUsui