Reputation: 20224
In my result, I want to jump arbitrarily between the rows.
In my table, I have a field next_set
. I start at row 1, which has next_set=3
, so I process row 3 next, which tells me to look at row 2 afterwards, and so on.
In php/mysql I did this with mysql_data_seek. How do I achieve it in C# / SQL Server?
Upvotes: 0
Views: 1098
Reputation: 726589
SqlDataReader
is forward-only, it does not allow jumping arbitrarily. However, you have several approaches that you could take here to overcome this problem:
DataSet
object which allows navigation of its DataTable
objects, orUpvotes: 2
Reputation: 43023
You cannot jump to some arbitrary position with SqlDataReader
. From MSDN description:
Provides a way of reading a forward-only stream of rows from a SQL Server database.
You can only move forward one step at the time.
To get around the issue:
You can either read all records into memory and seek in memory collection.
Use a DataTable
to get all records at once.
Upvotes: 2