views:

29

answers:

2

Hello,

I'm using a DataReader to display informations stored in a table.

I created Two button to go to next record and to go back.

In VB6 I used this code :

While Not Recordset1.EOF
Recordset1.MoveNext
End While

In ASP.NET I didn't find a way to do like it, because DataReader hasn't the EOF property.

EDIT :

While Not Recordset1.BOF
Recordset1.MovePrevious
End While

How can I convert this last code (VB6) to ASP.NET ??

+2  A: 

You use Read instead of MoveNext and it'll return false if there aren't any more records. So:

While rdr.Read()
    .... ' process this row
End While
ho1
The problem is that I must close the DataReader after every MyReader.Read(). So i don't remember the last record where I was.
dotNET
Also how can I go back without having any debug.
dotNET
@AZIRAR: Sorry, I didn't understand your exact question. I think you shouldn't be using a DataReader at all if you have a back button, DataReaders are forward only. I'd suggest that instead you use the DataReader to quickly load up a DataTable in memory and then you can read the previous or next record from that table easily enough. Here's an article about loading up the table: http://msdn.microsoft.com/en-us/library/system.data.datatable.load.aspx You could then even do `Dim rows() as DataRow = table.Select()` and end up with normal array etc.
ho1
A: 

Azirar, ho1 is correct in that you should use a DataTable. If you're updating after every post back and only need a single record you could still use a DataReader, but set up your SQL statement to get a single row (storing the appropriate information needed in your SQL statement (or better yet stored procedure) to get that single record back within query strings or session variables).

DaMartyr