Get all the row value of the data table

Hi Expertise
How can the robot extract all the row value when match some condition in each row, and get all the row value at once.

@lakshman
Please can you help?

1 Like

Hi @James90

I suppose you are trying to process an excel sheet or something similar right?

So what you can do is, read the data to a datatable variable. If your source is a excel file, you can use Read Range activity to read the data to a datatable
2. Now, use a For Each Row activity to loop through the datatable which you used to extract data
3. Within the For Each Row activity, you can use IF activity to match the records with a condition. So the IF activity condition should look something similar to this
row("ColumnName").ToString.Equals(<Your Match value/ variable should come here>)

in your dataset, if you don’t have a column name, then you can use the column index.
row(0).ToString.Equals(<same as before>)

If these are not string values which you are trying to match, you can try converting them to the required format. Let’s say its a number of Int32 format

    Int32.Parse(row("ColumnName").ToString) = 1234

Hope this helps!!

2 Likes

@James90

  1. Read the data from Excel using Read Range Activity and will give you output as dataTable.
  2. Then apply select query on that DataTable.

DataTable requiredRows = dataTableName.select("[ColumnName] = ‘Value’ AND [ColumnName] = ‘Value’ ").CopyToDataTable

It will fetch all matching rows from given input dataTable and will store result in new dataTable say ‘requiredRows’.

2 Likes

@lakshman
I have used read range, and gave if condition, row(0).tostring =“text” and then I want to get whole value of that row, and I don’t use column name.
Thank you

1 Like

@James90

You can access values in two ways either using Column Name or Column Index.

Here, you used row(0) means you are referring First column in the Excel file.

                       ForEach row in DataTableName
                          Int index = DataTableName.Rows.IndexOf(row) + 2
                          If row(0).Tostring = "Text"
                          Then:
                           DataRow dr = DataTableName(index)

Note: If you don’t have Column headers in your excel file, then write ‘+1’ instead of ‘+2’.

2 Likes

@lakshman
I got some error sir, please can you help me.

1 Like

@James90

Don’t write Index.ToString

Assign, DataRow = details(Index)

2 Likes

Buddy @James90
your condition and the workflow before if condition is fine buddy
i hope you are getting the index of the current row from the for each row loop and assigning it to a variable named Index…
let me tell you why you got this error first buddy @James90
–To get a particular row from a datatable we use to mention as datatable.Rows(Index of the row)
– where the index of the row argument passed above should be type int32
–as you were trying to convert the int32 to string, it was throwing error buddy and then we missed out Rows method rather passed like details(Index.ToString), actually it should be like below buddy
–so to get the whole datarow and assign it to a datarow variable of yours named DataRow
use like this buddy in your assign activity @James90
DataRow = details.Rows(Index)
this would give the whole row after validation done in if condition part buddy
Kindly try this and let know buddy @James90
Cheers

1 Like

@lakshman
It’s the same error.

@James90

Could you please go to that blue exclamatory mark and show me what is the exact error. So that i can help you in this.

1 Like

@Palaniyappan
I have made Index as Int32 put the DataRow = details.Rows(Index) also but having error again.

@lakshman
Here is the screenshot of errorerror3

1 Like

@James90

Make sure DataRow should be variable of type System.Data.DataRow. But you declared it as "Generic Value’. Change it and then try.

1 Like

Buddy kindly change the datatype of Datarow variable to system.data.datarow
The error occurred because we were trying to assign a datarow type to generic…this is what is mentioned in the error pop-up as well… buddy
You were almost done
Kindly try this and let know whether this works or not buddy
Cheers @James90

1 Like

@Palaniyappan
@lakshman
The output that I get is “system.data.DataRow.” not the data of that row? :frowning:

1 Like

Buddy i think you were trying to assign or used write line activity to print or pass the valuebof Datarow variable…
When you do that we need to mention the index argument as well like this
Datarow(0).ToString
Datarow(1).ToString
Where 0,1,2…are columnindex buddy
Cheers @James90

1 Like

@James90

Yes, we can’t print that DataRow directly. You have to print either passing Column Name or Index to DataRow.

DataRow(“ColumnIndex”).Tostring or DataRow(“ColumnName”).Tostring

1 Like

Were you able to get now buddy @James90

@lakshman
@Palaniyappan
I think we are having miss communication, here what the robot does is that, it check one column and if the condition is fulfilled then it will take all value of the same row. Like, When Robot compare column 4 of date, if date condition is fulfilled then how to get all the data of its same row(highlighted)?

2 Likes