Browsing the Departments and Products
Introduction. Now
we need to develop the ASPs that will likely be used for browsing the
products within a department. Now we
develop Products.asp. This will be presented after developing
stored procedures and displaying required images.
We will create two stored procedures. to retrieve the department/products relationships and then the products associated with the department. The following table displays the names of the stored procedures and the ASP file in which they are called. |
Stored Procedure | ASP Container |
sp_RetrieveDeptProducts
sp_RetrieveDept |
Products.asp |
Now, you need to get some images to be used for the
products on the department pages,
|
Product Images | |
Thumbnails | |
Image | Name |
sm_thimble.gif | |
sm_static.gif | |
sm_jazz.gif | |
sm_circle.gif | |
sm_hatsoff.gif | |
sm_lassos.gif | |
sm_DogCat.gif | |
sm_candles.gif | |
sm_hole.gif | |
sm_under.gif |
The Stored Procedures. Now I will list out the five stored procedures that you should create using SQL in almost the same way we created the tables. The first file should be called sp_RetrieveDeptProducts.asp.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_RetrieveDeptProducts @idDept int AS " & _ "select * from products, departmentproducts " & _ "where products.idproduct = departmentproducts.idproduct and departmentproducts.iddepartment = @idDept" connDeptProds.execute(strSQLCreate) connDeptProds.Close Set connDeptProds = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
The second file should be called sp_RetrieveDept.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_RetrieveDept @idDepartment int AS " & _ "select * from department where idDepartment = @idDepartment" connDeptProds.execute(strSQLCreate) connDeptProds.Close Set connDeptProds = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
Like all of the other ASPs based on CREATE SQL commands, these files need to be uploaded to your web and then executed once. After they have been executed, you should get an error if you try to execute them again because the stored procedures should already be there. After these sp_name.asp files have been used they should be removed from your space on the server. |
The Products.asp. The following
Products.asp
will
|
<%@ Language=VBScript %> <HTML> <!-- Products.asp - This page displays the products in a department. --> <!-- #include file="include/header.asp" --> <% ' Create an ADO database connection set dbDepartment = server.createobject("adodb.connection") ' Create the record set set rsDepartment = server.CreateObject("adodb.recordset") ' Open the connection using our SQL Server DSN-less connection dbDepartment.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=WildWillies;UID=cis; PWD=csatqu" dbDepartment.Open ' Build the SQL statement. We are calling the
stored procedure to retrieve the department ' Retrieve the product information to be displayed.
' Check the display flag. We will rotate the product images from left to right.
' Set the flag
' Move to the next row
loop |
Notice how this ASP makes use of the Header.asp and Footer.asp for navigation and page closure. |