Navigating a dataset 'randomly'

  • Thread starter Thread starter mklapp
  • Start date Start date
M

mklapp

Hello,

I retrieve all the Ids from a DB table. The 'current'
Id is used to retrieve all the columns associated with
that Id. I need to Move Next and Move Previous.
The DBEnumerator is a Forward-only tool.
A "For Each Row" solution would enclose nearly the
entire application in the loop and still would not work.
Since a "Find" is supported, maintaining a Global
index to step through the rows collection would not be
effective.
There are upwards of 14,000 rows in the table, so I am
not eager to use an array.
I must use a Web Service and ADO.NET disconnected
datasets.

How does one navigate forward and backward relative to
the current row without knowing the index (or can we
learn the index? The DBEnumerator was promising, but it
is forward only.

mklapp
 
Hi mklapp,

You'll have to use foreach to find a index of the current row.
Once you have the index, you can freely select index+-n row.
 
I was afraid it would come down to that. Frankly, I am
surprised the removal of such a basic functionality would
even be tolerated.

Thanks for ending the search

mklapp
 
Hi mklapp,

I think miha is right, you can maintain the current index after the first
time you find it in the DataTable.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
My particular problem lies in the fact this is an old app
(VB3 originally). The users expect identical
functionality and since interaction with the users is not
scheduled by the client....

The users like to MoveNext and MovePrevious.

To accomodate this, every time a find or select is
executed, I run a binary search on the table to locate
the retrieved row's position in the Rows collection. That
way I am looking at about 10 rows or less to retrieve the
index (not the key).

I have not yet genericized the routine to the point I
pass a table reference, a column index and a comparison
string but I suppose I will and I will keep it in
my 'toolkit'.

mklapp
 
Hi mklapp,

I think this is the only way to search for the index of the row in a
DataTable. Thanks for your feedback and sharing your experience with us in
the newsgroup.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top