This is the onbeforeopen event handler code. The code is executed just before the recordset object is loaded and changes the default SQL query to retrieve only records of books on special. The name BookRecords was assigned to this instance of the recordset object in the Binding data-bound Design Time Controls lesson. This function is executed just before the BookRecords recordset object is loaded.
Declare the variable querystring. It will contain the SQL query.
This statement assigns a SQL query to querystring. This SQL query specifies to return only records with a Status of 'S' (where Status = 'S'), which indicates that the book is on special.
The recordset object's setSQLText method is called and passes querystring as the parameter.
These lines define a standard HTML table and the table's first row.
This line begins a VBScript For Next loop that will execute once for each column in the database table.
The purpose of the For Next loop is to display the column names. This line gets the field name and displays it as table data in the HTML table row.
Now that the column headings are displayed, it's time to display one row in the HTML table for each row in the database table. This line uses the recordset control's end of file, EOF, property to execute a Do While loop until the end of the recordset is reached.
This For Next loop also executes one time for each column in the database table, this time to display the column data.
This line gets the database column value from the recordset and displays it in the HTML table.
After a row is displayed, the recordset object's MoveNext method is called to move to the next row. The Loop statement indicates the end of the Do While loop body.
This statement closes the recordset after all the rows are displayed.