How to find row number of data table when values from another data table

Say I have DT1
I am filtering the DT1 with some conditions, and getting DT2Filtered.
Now, I am trying to find the row number in DT1 with row values from DT2Filtered. But I am getting row number as -1 for all rows.

Inside For each Row activity,
For Each row in DT2Filtered
Rowindex = DT1.Rows.IndexOf(row)

Here I am getting -1 for RowIndex for all the rows supplied. please advise.

you are trying to find a DataRow object of datatable with another, this will always return -1.

If you can let everyone know why you are doing this or rather clarify your requirement, you’ll get better solution.

Hi @vigneshnkv
In your example row refers to the DataRow objects of DT2Filtered, thus searching for it’s rowindex in DT1 is returning -1. A simpler solution would be to have a primary key or a column that contains unique values for every row and using that to find connections between the 2 datatables.

If this is not an option, then can you share more details regarding your requirement?

The Requirement is:

  1. In an Excel1, get the data (DT1)
  2. Filter with some conditions, this will reduce the no of rows (DT2Filtered)
  3. take the values of Column “C” and compare with another Excel2’s Column “C” (say I have as DT3).
  4. If matches, then mark the Status as “pass” in Excel1 (DT1). to mark this, I need to find the correct row (from DT1). So I am trying to get the row index as mentioned above. Please suggest if there is any option for this.

hi @vigneshnkv
One solution would be to just add an Index column to DT2Filtered table which stores the index of the row respective to DT1 table.
Then you can use that index to find the row in DT1 after comparison with DT3.
I have attached an example of this solution. (12.4 KB)

If you are using DataTable.Select() method initially to get the filtered data you don’t have to use the index column strategy, since you won’t be needing DT2Filtered table.