Storing values of index row of datatable

Hello, I am looking for help on an automation solution.

Basically, I need to loop thru each row in a datatable, identify of a row contains a string - then once I’ve identified the row with the string, I need to store the index of that row, as well as the index of one row before and one row after into a list, so I can access the values of the list in another sequence. I was thinking that the Index row numbers would need to be stored as Int32, but not sure if there would be another solution, i cant find anything so far.


Hello @mbm10,

Could you please share with us a picture or something of your datatable? So we can understand much better!

Thanks :slight_smile:


If for example this is may datatable, i need to pull the Index value of the rows containing “STRING” in this case, it would be (2), (5), and (9). Then I need to pull the index value of each row one before, and one after the row containing “STRING”, so those values would be:
1 before: (1), (4), (8)
1 after: (3), (6), (10)

And I want to store these values into a list, and access them in another sequence.

I am of course starting the index at 0

In a non-LINQ implementation, you can do the following

loop over the data table rows with a for each row / for each row in data table - configure the output index of this activity e.g. to variable idx

  • check if the row is containing the search string
    • then add idx to a list
    • else: do nothing

later you can iterate over the index list e.g. within a for each Activity - item is the loop variable
access the rows
before: dtData.Rows(item-1)
matching: dtData.Rows(item)
after: dtData.Rows(item+1)

Just ensure that on first/last row of the data table not the non-existing rows are accessed

1 Like