Unable to find row index of data table by using function dt.rows.indexof(row), i am getting row index is -1, any one help me
I think you have used ‘ValuesTB’ as your data table. So, to get index you have to assign like the below -
Then it will work. Please try it.
Thanks & Regards,
thank you for your replay,
i don’t want row index value of valuesTB,
I want row index valu of dt datatable.
Hey @shaikjani, for this case ‘row’ doesn’t belong to your ‘dt’ data table, I mean ‘row’ is not a item of ‘dt’. That’s why this issue is coming. If you want index of ‘dt’ data table then you have to go like below -
- Use ‘For each row’ activity where you have to put ‘dt’ in data table field
- Assign ‘index’=‘dt.Rows.Indexof(row)’
- Use ‘Message Box’ to see index value.
Thanks & Regards,
I don’t want to rotate the loop for finding row index of ‘dt’ data table row, it is having thousands of records,
ValuesDB keeping one row and this same row having ‘dt’, so, in one iteration i want to know
row index in ‘dt’ table.
i thing you understand my scenario, any idea for this.
Even if the row from ValuesTB DataTable and dt DataTable has identical values - it is not the same row. Rows you want to match have different pointers in computer memory (they are separate objects), that is why dt.Rows.IndexOf method is returning -1.
In other words - a single DataRow object cannot belong to two different DataTables in the same time.
I suggest using your own ID to match rows and match ID values (e.g. using DataTable.Select method), not DataRow objects.
Thank you for your idea, finally got solution in one iteration only.
By using select query i retrivew one row from ExcelValues2 datatable and kept into
datarow array, then taken for each loop then passed row as item.
then it has given index value of ExcelValues2 datatable also. although those are
different objects also.