Browsing the Departments
Introduction. Now
we need to develop some ASPs that will likely be used for browsing the
departments. The file will be called Dept.asp.
This will be presented after developing
stored procedures and displaying required images.
We will create one stored procedure to retrieve the departments. The following table displays the name of the stored procedure and the ASP file in which it is called. |
Stored Procedure | ASP Container |
sp_RetrieveDepts | Dept.asp |
Finally, you need to get some images to be used on the
Dept.asp page,
|
Department Images | |
Image Name | Image |
funk.gif | |
dance.gif | |
western.gif | |
punk.gif | |
tshirts.gif |
The Stored Procedure. Now I will list out the stored procedure that you should create using SQL in almost the same way we created the tables. This file should be called sp_RetrieveDepts.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 connfoxFire, strSQLCreate Set connfoxFire = Server.CreateObject("ADODB.Connection") connfoxFire.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_RetrieveDepts AS " & _ "select * FROM department" connfoxFire.execute(strSQLCreate) connfoxFire.Close Set connfoxFire = 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 Dept.asp. The following
Dept.asp
will
|
<%@ Language=VBScript %> <HTML> <!-- Dept.asp - Displays the departments in the stores. --> <!-- #include file="include/header.asp" --> <b>Select from a department below:</b><BR><BR> <% ' Create an ADO database connection set dbDepts = server.createobject("adodb.connection") ' Create a record set set rsDepts = server.CreateObject("adodb.recordset") ' Open the connection using our SQL Server DSN-less connection dbDepts.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=WildWillies;UID=cis; PWD=csatqu" dbDepts.Open ' Call the stored procedure to retrieve the departments in the store. sql = "execute sp_RetrieveDepts" ' Execute the SQL statement set rsDepts = dbDepts.Execute(sql) ' We will use a flag to rotate images from left to right Flag = 0 ' Loop through the departments do until rsDepts.EOF ' Retrieve the field values to display the name, image and link to the ID of the department
' Check the flag
' Flip the flag
loop |
Notice how this ASP makes use of the Header.asp and Footer.asp for navigation and page closure. |