Re: ASP Question - Go to Next Record

by "Michael Gerholdt" <gerholdt(at)fredonia.edu>

 Date:  Fri, 10 Nov 2000 08:03:06 -0500
 To:  "Clyde Halsrud" <halsrud(at)erols.com>,
<hwg-languages(at)hwg.org>
 References:  erols
  todo: View Thread, Original


> Can bring back records from a database okay.  However, what stumps me
> is, when having retrieved a record, I would like to go to the next
> record vice going back to the original SQL statement.  Probably an easy
> answer.  Help
>

Are you returning one record at a time from the db server? If so, then
there's nothing for it except to return for the next record.

If you return a recordset then the webserver has in memory that set. In
script you can write a tablerow with a record, for example, and then use
rs.MoveNext

to move to the next record on the client-side (here the webserver is the
client of the db server)

and write the next table row. This generally done in a DO...LOOP, as:

While not rs.EOF
response.write "<tr><td>" & rs.("field1") & "</td>"
response.write "<td>" & rs("field2") & "</td></tr>"
rs.MoveNext
Loop

This will write the entire recordset to one web page.

If you are looking for something more dynamic, for instance, look at one
recordset at a time on a given web page, and then click on 'next' or
something to pull up a new webpage with the next record, and it is here you
wish to avoid multiple trips to the database, then consider pulling the
recordset into an array, closing the connection to the database, and then
pass the array from one page to the next in a hidden input field in a form.

Do this with rs.GetRows or even rs.Getstring

http://www.learnasp.com has some good info on the use of GetRows.

I most often, even if not moving through pages, pull a recordset into an
array this way. It is faster and easier to manipulate.

hope this helps,
Michael Gerholdt

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA