Skip to content Skip to sidebar Skip to footer

Can Somebody Explain How This Asp Code Works?

I wanted to echo some data from a table in my database and found this code: set rs = Server.CreateObject('ADODB.recordset') rs.Open 'Select name From users', conn do until rs.EOF

Solution 1:

rs is a recordset, which means a result of a database query.

The do until ... loop iterates (with the help of movenext) through all the rows found in the recordset (i.e. table users).

On all rows found the for each ... next loops through all fields found in the single row, which in this case is only the column name.


Solution 2:

See comments added to the code below

' Create a recordset. This is an object that can hold the results of a query.
set rs = Server.CreateObject("ADODB.recordset")

' Open the recordset for the query specified, using the connection "conn"
rs.Open "Select name From users", conn

' Loop over the results of the query until End Of File (EOF)
'   i.e. move one at a time through the records until there are no more left
do until rs.EOF
    ' For each field in this record
    for each x in rs.Fields

        ' Write out its value to screen
        Response.Write(x.value)

    ' Move to the next field
    next

    ' Move to the next record
    rs.MoveNext

' Continue to loop until EOF
loop

' Close the recordset
rs.close

Post a Comment for "Can Somebody Explain How This Asp Code Works?"