Database Reference
In-Depth Information
The RecordSet object has a command that returns a true if you have reached the end of
the record set. Switching to ASP again, we set up a while loop that will keep going until the
end of the record set is reached:
<%
while not MyRecordSet.EOF
To output HTML from within the ASP script, we use the response.write command. You
use this command by sending a string to it in quotes, or a function or object that returns a
string. As the next line needs a string made up of both text and the output of the query, we
can turn them all into one string by using the & operator. The script continues:
response.write “<TR><TD>” & MyRecordSet.fields(0) & “</TD><TD>” &
MyRecordSet.fields(1) & “</TD></TR>”
There are several ways of accessing the columns that are returned by the query. On this
occasion we send the fields command to the record set, with the number of the field speci-
fied by using:
MyRecordSet.fields(0)
This selects the first column returned by the query, which in this example is the host col-
umn. Field 2 is the user column. On this occasion the fields that are returned are in the
order which they were created, as we used the wildcard (*) in the select query to obtain
them. However, if we had sent the query:
SELECT user,host
FROM user;
then the columns would be returned in the select order. Bear this in mind when you are
using the fields command with the record set, as you may get unexpected results from not
specifying the exact column name.
Now that we have output the table row for this row of the record set, we can move to the
next record in the set by using the following:
MyRecordSet.MoveNext
This does not end the while loop, just moves to the next record. To trigger the end of the
while loop we use:
wend
%>
This will return to the top of the while loop and if the end of the record set has not been
reached repeat the processing for the next row in the set. If we are at the end of the set, the
Search WWH ::




Custom Search