Searching Products in the Store Manager
Introduction. Assuming
our list of products keeps growing, that is we keep stocking a larger
variety of CDs, we need to have an automated search.
This will be done in an ASP called SearchProducts.asp. This ASP will
rely on one stored procedure called sp_ManagerRetrieveProdSearch.
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_ManagerRetrieveProdSearch | SearchProducts.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 starting at some location in the table looking for something LIKE the inputted text. The file should be called sp_ManagerRetrieveProdSearch.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_ManagerRetrieveProdSearch " & _ "@intStartProdID int, " & _ "@intRowCount int, " & _ "@chrSearchText varchar(100) AS " & _ "set rowcount @intRowCount " & _ "select idProduct, chrProductName, intPrice from products " & _ "where idProduct >= @intStartProdID and chrProductName like '%' + @chrSearchText+ '%'" 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 SearchProducts.asp. You need to save this file and upload it to your StoreManager subdirectory. This ASP will do the following.
Call the file SearchProducts.asp. |
<%@ Language=VBScript %> <!-- #Include file="include/validatecheck.asp" --> <HTML> <!-- SearchProducts.asp - Provides a feature to search for products from the list. --> <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 ' Check to see if there is any search text. if request("SearchText") <> "" then
end if
end if
end if
end if
' Loop back |
After you upload this ASP and access it in your web after entering Shirt as the search text you should see something like the following. |
Notice that while we now have the search capability, we still don't have the navigation header, the ability to add new products and the links associated with each product still aren't active. In the next few pages we will implement this functionality. |