Listing Products in the Store Manager
Introduction. Now
we are getting into actually managing the products and the first thing
we need to do is list out the products in an intelligent fashion.
This will be done in an ASP called ListProducts.asp. This ASP will
rely on one stored procedure called sp_ManagerRetrieveProducts.
These will both be presented on this page and some discussion will
ensue.
The following table gives the ASP and stored procedure we will develop in this page. |
Stored Procedure | ASP Container |
sp_ManagerRetrieveProducts | ListProducts.asp |
The Stored Procedure. First we present the stored procedure. Remember, you do not need to implement the stored procedures, this is to illustrate what you would need to do if you had the correct permissions in your database. This stored procedure will retrieve a pre-specified number of product records. The file should be called sp_ManagerRetrieveProducts.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' Open a connection to our SQL Server database ' We will use the ADO Driver connection Dim connDeptProds, strSQLCreate Set connDeptProds = Server.CreateObject("ADODB.Connection") connDeptProds.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connDeptProds.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_ManagerRetrieveProducts " & _ "@intStartProdID int, @intRowCount int AS set rowcount @intRowCount " & _ "select idProduct, chrProductName, intPrice from products where idProduct >= @intStartProdID" connDeptProds.execute(strSQLCreate) connDeptProds.Close Set connDeptProds = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
As with all of the stored procedures you create, this
file would only need to be executed once in your database. After
that you should get an error that the stored procedure already
exists. Since this is linked to the WildWillies database you do not even
need to do this much. But, remember, if you do execute such an ASP
you can delete the ASP immediately after the stored procedure has been
created.
The ListProducts.asp. Now we will get to what is one of our main overall interfaces for managing products. You need to save this file and upload it to your StoreManager subdirectory. This ASP will do the following.
Call the file ListProducts.asp. |
<%@ Language=VBScript %> <!-- #Include file="include/validatecheck.asp" --> <HTML> <!-- ListProducts.asp - Lists the products in the store. --> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <!-- #include file="include/navinclude.asp" --> <% ' Create an ADO database connection set dbProducts = server.createobject("adodb.connection") ' Create the record set set rsProducts = server.CreateObject("adodb.recordset") ' Open the connection using our SQL Server DSN-less connection dbProducts.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=WildWillies;UID=cis; PWD=csatqu" dbProducts.Open ' The products will not all be displayed at once. We ' want to set the Product Increment in a session variable. ' If the product increment is not set, then we will set ' it. In this case, we are defaulting it to 4. if session("ProdInc") = "" then
end if
end if
end if
end if %>
' Loop back |
After you upload this ASP and access it in your web you should see something like the following. |
Notice the navigation header, the ability to add new products, the links associated with each product, the scrolling capability and the search capability aren't yet active. In the next few pages we will implement this functionality. |