Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5 Building Your Product Catalog database Objectives Create Database. Create Table. Connect to Database. Use ASP Script to add new products. Use.

Similar presentations


Presentation on theme: "Chapter 5 Building Your Product Catalog database Objectives Create Database. Create Table. Connect to Database. Use ASP Script to add new products. Use."— Presentation transcript:

1 Chapter 5 Building Your Product Catalog database Objectives Create Database. Create Table. Connect to Database. Use ASP Script to add new products. Use ASP Scripts to update existing product information.

2 Database Def: An organized collection of related information. Ex: MS Access, MS SQL Server, Oracle, Sybase, ingress etc. The first step in creating online store is to create a database to hold information about your products. MS Access is used to create database.

3 Creating Database Launch MS Access by selecting Start, Programs, MS Access. From the initial dialog box, choose the option to create a new database using a blank Access database. Within the File New Database dialog box, name your new database “storeDB” and save your new database to your hard drive.

4 Tables Database all by itself isn't particularly useful. Add one or more tables in a database before storing the information. A database table is structured like a spreadsheet or ledger. It contains one or more rows divided into one or more columns. Each column has a name & is used to store a particular type of information. Each row in a database table represents a distinct record.

5 Creating Tables Launch MS Access by selecting Start, Programs, MS Access. Select the option to open an existing file & select the database named storeDB. After you open the storeDB database, double-click the item labeled Create table in Design view. Enter the information into design view table grid. Make the product_id column into the table’s primary key by selecting the column within the grid and clicking the icon of the key. Save the new table by clicking Save and entering the same products.

6 Connecting to a Database To access the database within an ASP page, open a database connection but before that the physical location of the database has to be provided to ASP page & this is done with Data Source Name (DSN) Two types of DSN: File DSN – DB connection information is stored in a file. System DSN - DB connection information is stored in a computer’s registry.

7 Create System DSN Open Control Panel by selecting Start, settings, Control Panel. Click on ODBC Data sources applet. Select the tab labeled System DSN and click Add. Select the MS Access driver and click finish. In the ODBC MS Access Setup dialog box, click the button labeled Select and navigate through your Hard Drive to the database named storeDB. Click OK. Enter accessDSN for the Data Source Name and click OK. Click OK to close the ODBC Data Sources applet.

8 ActiveX Data Objects (ADO) is used to open database connection. ADO is a collection of objects that allows you o work with databases within your ASP Scripts. ASP script to open database connection: <% Set Con = Server.CreateObject(“ADODB.Connection”) Con.Open “accessDSN” %>

9 Inserting records into Table Syntax: Insert into table_name(column_list) values (value_list). ASP script: <% Set Con = Server.CreateObject(“ADOB.Connection”) Con.Open “accessDSN” Sqlstring=“Insert into products (p_name,p_price) &_ “VALUES(‘Gift Basket’,34.54)” Con.Execute sqlstring Con.close %>

10 Updating records in Table Modifying existing records. Syntax: Update table_name SET column_name = expression where column_name = expression. Ex: Update product set product_price=45.00 where product_id=17.

11 ASP Script to Update table <% Set Con = Server.CreateObject(“ADOB.Connection”) Con.Open “accessDSN” Sqlstring=“Udate products &_ “Set p_price = 45.00”&_ “where p_name = ‘Gift Basket’ “ Con.Execute sqlstring Con.close %>

12 Retrieving Product Names <% Set Con = Server.CreateObject(“ADOB.Connection”) Con.Open “accessDSN” Sqlstring=“select p_name from products” Set RS=con.execute(sqlstring) While not RS.EOF %> <% RS.MoveNext Wend %>


Download ppt "Chapter 5 Building Your Product Catalog database Objectives Create Database. Create Table. Connect to Database. Use ASP Script to add new products. Use."

Similar presentations


Ads by Google