The setOrders.asp module adds shopping cart contents to an order table by executing several commands in stored procedures over one connection that uses input and output parameters. 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_add_orders_header"
cmdPubs.CommandType = adCmdStoredProc
After creating a Command object, the application sets up a Parameter object by using the following steps:
@piiCustomerID of type Integer with a size of 4
@picTotalOrderPrice of type Currency with a size of 8
@picShippingCharges of type Currency with a size of 8
@picSalesTax of type Currency with a size of 8
@poiNextOrderID of type Integer with a size of 4
The corresponding code follows:
set p = cmdPubs.Parameters
p.Append cmdPubs.CreateParameter("@piiCustomerID", adInteger,
adParamInput, 4)p.Append cmdPubs.CreateParameter("@picTotalOrderPrice", adCurrency,
adParamInput, 8)
p.Append cmdPubs.CreateParameter("@picShippingCharges", adCurrency,
adParamInput, 8)p.Append cmdPubs.CreateParameter("@picSalesTax", adCurrency,
adParamInput, 8)
p.Append cmdPubs.CreateParameter("@poiNextOrderID", adInteger,
adParamOutput, 4)
The following code specifies the values to assign to the input parameters:
cmdPubs("@piiCustomerID") = Session("CustomerID")cmdPubs("@picTotalOrderPrice") = Session("TotalOrderPrice")
cmdPubs("@picShippingCharges") = Session("ShippingCharges")
cmdPubs("@picSalesTax") = Session("SalesTax")
The following code specifies the connection to use and then executes a command:
Set cmdPubs.ActiveConnection = connPubs
cmdPubs.Execute
The following code assigns the values of the output parameters to session variables:
Session("OrderID") = cmdPubs("@poiNextOrderID")
The following code clears the contents of the Command object:
Set cmdPubs = Nothing
The following code clears the contents of the Parameter object:
Set p = Nothing
Resets the Command object by using the following steps:
The corresponding code follows:
cmdPubs.CommandText = "sp_add_order_line_item"cmdPubs.CommandType = adCmdStoredProc
After creating a Command object, the application sets up a Parameter object by using the following steps:
@piiOrderNumber of type Integer with a size of 4
@piiLineNumber of type Integer with a size of 4
@piiProductID of type Integer with a size of 4
@piiQuantity of type Integer with a size of 4
@picPrice of type Currency with a size of 4
The corresponding code follows:
set pp = cmdPubs.Parameterspp.Append cmdPubs.CreateParameter("@piiOrderNumber", adInteger,
adParamInput, 4)pp.Append cmdPubs.CreateParameter("@piiLineNumber", adInteger,
adParamInput, 4)pp.Append cmdPubs.CreateParameter("@piiProductID", adInteger,
adParamInput, 4)pp.Append cmdPubs.CreateParameter("@piiQuantity", adInteger,
adParamInput, 4)pp.Append cmdPubs.CreateParameter("@picPrice", adCurrency,
adParamInput, 8)
The following code assigns the values of session variables to temporary variables:
aiSKProductIDs = session("aiSKProductIDs")aiSKCategoryIDs = session("aiSKCategoryIDs")
aiSKProductQuantitys = session("aiSKProductQuantitys")
aiSKProductPrices = session("aiSKProductPrices")
acSKProductNames = session("acSKProductNames")
acSKProductDescriptions = session("acSKProductDescriptions")
The following code specifies the values to assign to the input parameters:
cmdPubs("@piiOrderNumber") = Session("OrderID")cmdPubs("@piiLineNumber") = icmdPubs("@piiProductID") = aiSKProductIDs(i)
cmdPubs("@piiQuantity") = 1
cmdPubs("@picPrice") = aiSKProductPrices(i)
The following code constructs an SQL query:
SQL = "insert OrderLineItem "SQL = SQL & "values (" SQL = SQL & Session("OrderID") & ", "
SQL = SQL & i & ", "
SQL = SQL & aiSKProductIDs(i) & ", 0, "
SQL = SQL & aiSKProductQuantitys(i) & ", 0, "
SQL = SQL & "null, "
SQL = SQL & "null, "
SQL = SQL & aiSKProductPrices(i)
SQL = SQL & ")"
The following code executes a command directly through the Connection object:
connPubs.Execute(SQL)
The following code specifies the connection to use and then executes a command:
Set cmdPubs.ActiveConnection = connPubs
cmdPubs.Execute