Displaying Users Based on ASPs and SQL Stored Procedures
Introduction.
Now that we have added some users to our database it can be worthwhile to
display them. This will prove to be much simpler than adding a user. Now we only need one stored procedure since we do not require someone to have registered in order to display the other users. You want to create the following file called sp_RetrieveAllUsers.asp. Then you need to change the name of the table yourInitials_UserRegistration and the name of the stored procedure yourInitials_RetrieveAllUsers in the appropriate places and upload it to your directory that contains a copy of the adovbs.inc. Then when you execute this ASP via your browser on the web it will create the appropriate stored procedure. |
<%@ 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=ASP_SQL;UID=learn; PWD=learnSQL" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE yourInitials_RetrieveAllUsers AS " & _ "select * from yourInitials_UserRegistration" connfoxFire.execute(strSQLCreate) connfoxFire.Close Set connfoxFire = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
This code will execute only once to create the stored
procedure unless you get me to remove it. After executing this you
probably should delete this file from your web directory. Notice that the SQL is quite simple and does nothing more than retrieve all the records from your table. It doesn't require the ASP to supply it with any input parameters. This will then be used by the processing script we are about to develop to display the entries in a table. The Processing Script Page. Here is the DisplayUser.asp which we will discuss after. You need to change the name of the stored procedure yourInitials_RetrieveAllUsers |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <!--#include File="ConnectToUserRegistration.asp"--> <% ' Instantiate a recordset object and retrieve the info from the table Dim rsRegisteredUsers, sqlStatement Set rsRegisteredUsers = Server.CreateObject("ADODB.Recordset") ' Call the stored procedure to retrieve ' all of the records in the table sqlStatement = "execute yourInitials_RetrieveAllUsers " Set rsRegisteredUsers = connUserRegister.Execute(sqlStatement) ' Display the contents of the table ' This first section initializes the table ' and fills in the column headers Response.Write "<P>" & "<center><font size = 5><b>" & "The Registered Users" & "</b></font></center>" Response.Write "<P>" & "<table align = center border = 2><tr><td><font size = 4><b>" & "Name" & "</b></font></td>" Response.Write "<P>" & "<td><font size = 4><b>" & "<center>E-Mail<BR>Address</center>" & "</b></font></td>" Response.Write "<P>" & "<td><font size = 4><b>" & "<center>Registration<BR>Date</center>" & "</b></font></td>" Response.Write "<P>" & "<td><font size = 4><b>" & "<center>Age</center>" & "</b></font></td>" Response.Write "<P>" & "<td><font size = 4><b>" & "<center>Credit<BR>Card</center>" & "</b></font></td>" Response.Write "<P>" & "<td><font size = 4><b>" & "<center>Annual<BR>Income</center>" & "</b></font></td>" Response.Write "<P>" & "<td><font size = 4><b>" & "<center>Interests</center>" & "</b></font></td>" Response.Write "<P>" & "<td><font size = 4><b>" & "<center>Education</center>" & "</b></font></td></tr>"
' Now we loop through all of
the table's entries
Loop |
The following is a display of what shows up in my table. |