The Product.asp module retrieves and displays the information of one product. The main steps are:
This application first uses the following steps to define a connection to a database by setting up a Connection object to reference the data source:
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 application sets up a Command object by using the following steps:
The corresponding code follows:
Set cmdPubs = Server.CreateObject("ADODB.Command")cmdPubs.CommandText = "sp_get_product"
cmdPubs.CommandType = adCmdStoredProc
After creating a Command object, the application sets up a Parameter object by using the following steps:
@ piiProductID of type Integer with a size of 4
The corresponding code follows:
set p = cmdPubs.Parameters
p.Append cmdPubs.CreateParameter("@piiProductID", adInteger, adParamInput, 4)
The following code specifies the value to assign to the input parameter:
cmdPubs("@piiProductID") = Request("iProductID")
The following code specifies the connection to use and then executes the query that returns the Recordset object:
Set cmdPubs.ActiveConnection = connPubs
set rsPubs = cmdPubs.Execute
The following code loops through the Recordset, displays a record, and closes the connection when it reaches the end of the Recordset:
if rsPubs.EOF then
%>
<TR>
<TD>
No items found
<TD>
<%
else
do until rsPubs.EOF
htmlProductID = rsPubs("ProductID")
htmlCategoryID = rsPubs("CategoryID")
htmlProductPrice = rsPubs("ProductPrice")
htmlProductName = rsPubs("ProductName")
htmlProductDescription = rsPubs("ProductDescription")
<TABLE> <TR> <TD><H1><% = htmlProductName %></H1>
<TD><H2><FONT COLOR="RED">$<% = htmlProductPrice %>
</FONT><H2> <TR> <TD><H5>Enter Quantity: <INPUT TYPE="Text" NAME=cQuantity SIZE=3 VALUE=1></H5> <TR>
<TD><H4><% = htmlProductDescription %></H4>
<BR>
<BR>
<%
rsPubs.MoveNext
Loop
rsPubs.close
end if
%>