The getCategories.asp module gets a list of Product Categories by storing a Recordset into session variable arrays. The main steps are:
This application first defines a connection to a database by setting up a Connection object to reference the data source. The steps taken are:
The corresponding code follows:
Set connPubs = Server.CreateObject("ADODB.Connection")
connPubs.ConnectionTimeout = Session("accts_ConnectionTimeout")
connPubs.CommandTimeout = Session("accts_CommandTimeout")
connPubs.ConnectionString = "DSN=Sample;UID=sa;"
connPubs.open
After creating and opening a connection, the following code executes a query that returns the number of rows in the database:
SQL = "SELECT row_count = count(*) from Category"Set rsPubs = connPubs.Execute(SQL)iRowCount = rsPubs("row_count")
The following code executes a query that returns a Recordset object. Then the application loops through the Recordset, extracts the values of the Field objects, and stores the values in session variable arrays. The application closes the connection when it reaches the end of the Recordset.
SQL = "SELECT * from Category"Set rsPubs = connPubs.Execute(SQL)
i = 1
do until rsPubs.EOF
aipkCategoryIDs(i) = rsPubs("CategoryID")
acCategoryNames(i) = rsPubs("CategoryName")
acCategoryDescriptions(i) = rsPubs("CategoryDescription")
rsPubs.MoveNext
i = i+1
Loop
rsPubs.close
Session("aipkCategoryIDs") = aipkCategoryIDs
Session("acCategoryNames") = acCategoryNames
Session("acCategoryDescriptions") = acCategoryDescriptions