ASP Database Fundamentals (Part 2) - What If There Is More Than One Row?
(Page 8 of 9 )
Now it’s time for the fun part. We’ve got a recordset containing multiple rows. How do we show all of the data?
Well, we are able to move through the recordset using different methods. The most important methods for this are “MoveFirst”, “MoveLast”, “MoveNext”, and “MovePrevious”. The meanings of these methods are self describing.
But when moving through a recordset you must know when to stop. This is done for the most part by checking two properties. These are EOF (End of records) and BOF (Beginning of records).
Here is an example:
set rs
= Server.CreateObject("ADODB.recordset") rs.open “select * from Customers”, conn do until rs.EOF response.write “The customer’s name is “ & _ rs(“FirstName”) & “ “ & rs(“LastName”) rs.MoveNext loop rs.close set rs = nothing
There are many more properties and methods for the recordset object that allow you to many things. This article is aimed at only the basics. To learn to do things such as convert the recordset to an array, or to move the recordset pointer to any position within the recordset, I would suggest reading a tutorial more focused on the details of the subject.
Next: What’s Next? >>
More ASP Articles
More By Rich Smith