17 – Persistent data storage: relational databases and ADO

Slides:



Advertisements
Similar presentations
Basics of Database Programming with VB6
Advertisements

Connecting to Database 21 Feb Database Options Can use many different databases in conjunction with php. – MySql; MS Access; Oracle; etc etc Most.
Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon Page 1 04 – Database Design: Forms. Mark Dixon Page 2 Session Aims & Objectives Aims –To allow easier data entry using forms Objectives, by.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Modular Design in ASP.
Mark Dixon Page 1 03 – Database Design: Multiple Tables.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: HTML and Client-side code.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 SOFT – Module Introduction.
Mark Dixon Page 1 21 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Entity-relationship diagrams.
Mark Dixon, SoCCE SOFT 131Page 1 22 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 18 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon Page 1 20 – Modular Design in ASP. Mark Dixon Page 2 Session Aims & Objectives Aims –Highlight modular design techniques in ASP Objectives,
Mark Dixon, SoCCE SOFT 131Page 1 18 – Structured Query Language.
Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 19 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 08 – Web applications: HTML and ActiveX controls.
Mark Dixon, SoCCE SOFT 131Page 1 19 – Databases: Multiple Tables.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: Writing data to Databases using ASP.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
Mark Dixon 1 20 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 5 – Persistent data storage: relational databases.
M Dixon 1 Web-Application Development Workshop. M Dixon 2 Session Aims & Objectives Aims –to introduce the main concepts involved in creating web-applications.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Mark Dixon Page 1 24 – Object Oriented Programming in ASP.
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 18 – Web applications: Server-side code (PhP)
Mark Dixon Page 1 21 – Persistent data storage: relational databases and MySQL.
Mark Dixon 1 05 – JSP Databases: Multiple Tables.
Mark Dixon 1 06 – JSP Databases: Multiple Tables.
Lecture Note 10: Simple Database Techniques. Introduction –Database System –Access, SQL Server and others. –Microsoft Access - Interacting with this databases.
How to Connect to Database ODBC (Open Database Connectivity) ADO (ActiveX Data Object) ASP Code To Connect to Database Recordset Object Navigating through.
Mark Dixon Page 1 Web-Application Development Workshop.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
Mark Dixon 1 21 – Databases: Multiple Tables. Mark Dixon 2 Questions: Databases How many records are in the following table? How many fields does the.
M Dixon 1 Web-Application Development Workshop. M Dixon 2 Session Aims & Objectives Aims –to introduce the main concepts involved in creating web-applications.
Mark Dixon 1 21 – Databases: Multiple Tables and Writing Data.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Web applications: Databases & ASP.
Lab 8 Data Access Using Microsoft ActiveX Data Object (ADO)
Mark Dixon Page 1 15 – Web applications: Server-side code (ASP)
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.
Mark Dixon, SoCCE SOFT 131Page 1 12 – Databases: Structured Query Language.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 6: Accessing a database with PHP Rob Gleasure robgleasure.com.
Mark Dixon, SoCCE SOFT 131Page 1 14 – Databases: Multiple Tables.
1 ADO Activex Data Objects. 2 ADO ADO allows users to access data easily from many existing databases (such as Access or Paradox) From ODBC compliant.
Chapter 5 Building Your Product Catalog database Objectives Create Database. Create Table. Connect to Database. Use ASP Script to add new products. Use.
Generating XML Data from a Database Eugenia Fernandez IUPUI.
 2 Data Object Library approaches ◦ DAO (Data Access Objects)  Original access strategy (up to VB6)  Closely linked to MS Access ◦ ADO (ActiveX Data.
Getting Started with Application Software
9 – Web applications: Server-side code (ASP)
18 – Databases: Structured Query Language
23 – Object Oriented Programming in ASP
17 – Modular Design in ASP.
Project 9 Creating Pop-up Windows, Adding Scrolling Messages, and Validating Forms.
COMP3241 E-Commerce Technologies
Chapter 10 ASP and Data Store Access
Accessing Databases with ADO.NET, Handling Exceptions, and Printing
Working With Databases
19 – Databases: Multiple Tables
Presentation transcript:

17 – Persistent data storage: relational databases and ADO

Session Aims & Objectives To introduce the fundamental ideas involved in persistent data storage and relational databases Objectives, by end of this week’s sessions, you should be able to: create a relational database table create a web page (ASP) that displays data from a single table in a database using ActiveX Data Objects (ADO)

Persistent Data Storage So far all programs lose data when closed Not realistic typically data stored to persistent storage device (e.g. hard disk, key drive, floppy disk, CD-RW) Use either flat files database (relational, or object oriented)

Example: People (Specification) User requirement: Display list of people from database online How: Combine our knowledge of: ASP (active server pages) ADO (activeX data objects)

Example: People (Database) Information organised into tables (e.g. person) fields (e.g. phone) records (e.g. 1 Dixon Mark 01752 232556 …) Record Field Person ID Surname Forenames Phone email 1 Dixon Mark 01752 232556 mark.dixon@plymouth.ac.uk 2 Smith John 01752 111111 john.smith@john.smith.ac.uk 3 Jones Sally 01752 888888 sally.jones@sally.jones.com 4 Bloggs Fred 01752 123123 fred.bloggs@aaaaaa.com 5 Johnson Genny 01752 987987 genny@bbbb.cccc.com

Example: Music (Database) How many fields? How many records? Track Track Title Artist Name Country Paranoid Black Sabbath UK Falling in Love Aerosmith US Pink Love in an Elevator Smooth Criminal Alien Ant Farm Meaning of Life Disturbed The Game Voices Down with the Sickness

Database Management Systems DBMS provides facilities for: creating and changing databases add/remove records add/remove fields add/remove data For example: Microsoft Access dBase Borland Paradox MySQL Microsoft SQL Server Oracle home/small business large scale

MS Access Music database

ActiveX Data Objects (what & why) ActiveX Data Objects (ADO) common database interface allow you to write code for any DBMS MS Access VB or VB Script code ADO MS SQL Server … DB front end …

ADO Record Set Object Used to interact with tables Properties Methods BOF: true if at start of record set (before first record) EOF: true if at end of record set (after last record) Fields: used to get and set data values Methods Open: used to open record set MoveFirst: moves focus to first record MovePrevious: moves focus to previous record MoveNext: moves focus to next record MoveLast: moves focus to last record Close: closes record set

Using Record Sets Connection string – identify database <% Const cs = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Music.mdb; Persist Security Info=False" Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() … rs.MoveNext() Loop rs.Close() rs = Nothing %> Open record set with table Move to next record Close record set

Connection Strings: UDL files Generate connection strings Right click on desktop Select New, Text Document Rename to *.UDL (Yes to warning message) Double click Select provider Click Next Select or enter DB name Click Test Connection button Click OK Open with Notepad, cut & paste text

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb; " Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb; " Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb; " Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb;" Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs Dixon

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb;" Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs Dixon Smith

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb;" Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs Dixon Smith Jones

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb;" Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs Dixon Smith Jones Bloggs

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb;" Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs Dixon Smith Jones Bloggs Anderson

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb;" Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs Dixon Smith Jones Bloggs Anderson

Example: People rs <% People.aspx <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb; " Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write("<br>") rs.MoveNext() Loop rs.Close() rs = Nothing %> </body> </html> rs Dixon Smith Jones Bloggs Anderson

Example: People v2 Use procedure to separate: code detail html <script runat="server"> Const cs = "…" Sub DisplayPeople() Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value & "<br>") rs.MoveNext() Loop rs.Close() rs = Nothing End Sub </script> <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% DisplayPeople() %> </body> </html> Use procedure to separate: code detail html

Tutorial Exercise: People Task 1: Create your own People database: Open MS Access Create a new database file Create a new table Create fields Enter data Task 2: Create the People v2 asp page (as per the lecture) to display data from the database. Task 3: Modify your page so that it displays phone number as well as the person's name. Task 4: Modify your page so that the user can type a letter, and only names starting with that letter are displayed. Task 5: Modify your page so that the user can type a series of numerical digits and only phone numbers containing those digits are displayed. Task 6: Modify your page so that it displays the data in an html table. Hint: use Response.Write to insert the appropriate tags.

Tutorial Exercise: Music Task 1: Create your own Music Database. Task 2: Create an asp page to display data from this database. Task 3: Modify your page so that the user can type the name of an artist, and only tracks by that artist are displayed Task 4: Make your page case in-sensitive (i.e. UPPER or lower case makes no difference)