Initializing the Tables
Introduction. Previously,
we created the tables for our on-line store and shopping
experience. Now we need to initialize the tables with some dummy
data in order to test it. The first thing we need to do is make
sure we are keeping track of a ShopperID for everyone visiting our
web. This can also be used to uniquely identify these
shoppers in other tables in our web.
The following Global.asa file is executed when the session starts. |
<SCRIPT LANGUAGE=VBScript RUNAT=Server> ' Subroutine is fired off when the session starts Sub Session_OnStart ' Start the shopper ID at 0 session("idShopper") = 0 End Sub </SCRIPT> |
Now we need to start creating some ASPs that will execute our SQL to insert some initializing data into our tables. Our first program is called LoadDepartments.asp. |
<%@ Language=VBScript %> strSQLCreate = "insert into department(chrDeptName, txtDeptDesc, chrDeptImage) values('Cool Backstreet
Jazz'," & _ strSQLCreate = "insert into department(chrDeptName, txtDeptDesc, chrDeptImage) values('Crying
Westerns'," & _ strSQLCreate = "insert into department(chrDeptName, txtDeptDesc, chrDeptImage) values('Punked
Out'," & _ strSQLCreate = "insert into department(chrDeptName, txtDeptDesc, chrDeptImage) values('Wild
T-Shirts'," & _ |
The next ASP should be called LoadProducts.asp. |
<%@ Language=VBScript %> strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(1,1)" strSQLCreate = "insert into
products(chrProductName, txtDescription, chrProductImage, intPrice,
intActive)" & _ strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(1,2)" strSQLCreate = "insert into
products(chrProductName, txtDescription, chrProductImage, intPrice,
intActive)" & _ strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(2,3)" strSQLCreate = "insert into
products(chrProductName, txtDescription, chrProductImage, intPrice,
intActive)" & _ strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(2,4)" strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(3,5)" strSQLCreate = "insert into
products(chrProductName, txtDescription, chrProductImage, intPrice,
intActive)" & _ strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(3,6)" strSQLCreate = "insert into
products(chrProductName, txtDescription, chrProductImage, intPrice,
intActive)" & _ strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(4,7)" strSQLCreate = "insert into
products(chrProductName, txtDescription, chrProductImage, intPrice,
intActive)" & _ strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(4,8)" strSQLCreate = "insert into
products(chrProductName, txtDescription, chrProductImage, intPrice,
intActive)" & _ strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(5, 9)" strSQLCreate = "insert into
products(chrProductName, txtDescription, chrProductImage, intPrice,
intActive)" & _ strSQLCreate = "insert departmentproducts(idDepartment, idProduct) values(5, 10)"
|
The next ASP should be called LoadAttributes.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 connLoad, strSQLCreate Set connLoad = Server.CreateObject("ADODB.Connection") connLoad.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connLoad.Open ' Creating the SQL Strings to insert data into the tables strSQLCreate = "insert into attributecategory(chrCategoryName) values('Size')" connLoad.execute(strSQLCreate) strSQLCreate = "insert into attributecategory(chrCategoryName) values('Color')" connLoad.execute(strSQLCreate) strSQLCreate = "insert into attribute(chrAttributeName, idAttributeCategory) values('Small', 1)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into attribute(chrAttributeName, idAttributeCategory) values('Medium', 1)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into attribute(chrAttributeName, idAttributeCategory) values('Large', 1)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into attribute(chrAttributeName, idAttributeCategory) values('X-Large', 1)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into attribute(chrAttributeName, idAttributeCategory) values('Red', 2)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into attribute(chrAttributeName, idAttributeCategory) values('Blue', 2)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into attribute(chrAttributeName, idAttributeCategory) values('Green', 2)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into attribute(chrAttributeName, idAttributeCategory) values('White', 2)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(1, 9)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(2, 9)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(3, 9)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(4, 9)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(5, 9)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(6, 9)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(7, 9)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(8, 9)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(1, 10)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(2, 10)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(3, 10)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(4, 10)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(5, 10)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(6, 10)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(7, 10)" connLoad.execute(strSQLCreate) strSQLCreate = "insert into productattribute(idAttribute, idProduct) values(8, 10)" connLoad.execute(strSQLCreate) connLoad.Close Set connLoad = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
Now that these records have been initialized in our tables we can start developing the store in future web pages. |