Mark Dixon Page 1 17 – Persistent data storage: relational databases and ADO.

Slides:



Advertisements
Similar presentations
Basics of Database Programming with VB6
Advertisements

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, 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, SoCCE SOFT 131Page 1 16 – Passing Data between pages: Sessions, Query Strings, & Self Posting.
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.
Copyright © 2001 by Wiley. All rights reserved. Chapter 9: Introduction to Working with Databases in Visual Basic Database Concepts Relational Database.
IE 423 – Design of Decision Support Systems Introduction to Data Base Management Systems and MS Access.
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.
XP 1 New Perspectives on XML Binding XML Data with Internet Explorer.
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.
ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard set of objects to refer.
Database Management Systems.  Database management system (DBMS)  Store large collections of data  Organize the data  Becomes a data storage system.
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.
Database Management Systems CS 420. Topics Outline 1. Introduction 2. HTML Review 3. VBScript 4. Access DBMS 5. Relational Database 6. Design Process.
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.
Using databases ActiveX Data Objects (ADO) Connecting to a database Reading data from a database Inserting, updating and deleting records Using databases.
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.
18 – Databases: Structured Query Language
Chapter 10 ASP and Data Store Access
Working With Databases
17 – Persistent data storage: relational databases and ADO
19 – Databases: Multiple Tables
Presentation transcript:

Mark Dixon Page 1 17 – Persistent data storage: relational databases and ADO

Mark Dixon Page 2 Session Aims & Objectives Aims –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)

Mark Dixon Page 3 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)

Mark Dixon Page 4 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)

Mark Dixon Page 5 Record Field Example: People (Database) IDSurnameForenamesPhone 1DixonMark SmithJohn JonesSally BloggsFred JohnsonGenny01752 Information organised into –tables (e.g. person) –fields (e.g. phone) –records (e.g. 1 Dixon Mark …) Person

Mark Dixon Page 6 How many fields? How many records? Example: Music (Database) Track TitleArtist NameCountry ParanoidBlack SabbathUK Falling in LoveAerosmithUS PinkAerosmithUS Love in an ElevatorAerosmithUS Smooth CriminalAlien Ant FarmUS Meaning of LifeDisturbedUS The GameDisturbedUS VoicesDisturbedUS Down with the SicknessDisturbedUS Track

Mark Dixon Page 7 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

Mark Dixon Page 8 MS Access Music database

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

Mark Dixon Page 10 ADO Record Set Object Used to interact with tables Properties –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

Mark Dixon Page 11 Using Record Sets <% 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 %> Connection string – identify database Open record set with table Move to next record Close record set

Mark Dixon Page 12 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

Mark Dixon Page 13 People.aspx Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs

Mark Dixon Page 14 People.aspx Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs

Mark Dixon Page 15 People.aspx Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs

Mark Dixon Page 16 Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs Dixon People.aspx

Mark Dixon Page 17 Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs Dixon Smith People.aspx

Mark Dixon Page 18 Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs Dixon Smith Jones People.aspx

Mark Dixon Page 19 Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs Dixon Smith Jones Bloggs People.aspx

Mark Dixon Page 20 Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs Dixon Smith Jones Bloggs Anderson People.aspx

Mark Dixon Page 21 Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs Dixon Smith Jones Bloggs Anderson People.aspx

Mark Dixon Page 22 People.aspx Example: People Personal Address Book Personal Address Book <% 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(" ") rs.MoveNext() Loop rs.Close() rs = Nothing %> rs

Mark Dixon Page 23 Example: People v2 Const cs = "Provider=…;Data Source=D:\People.mdb;" Sub DisplayPeople() Dim rs rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) Do Until rs.EOF() Response.Write(rs.Fields("Surname").Value) Response.Write(" ") rs.MoveNext() Loop rs.Close() rs = Nothing End Sub Personal Address Book Personal Address Book <% DisplayPeople() %> Use procedure to separate: –code detail –html

Mark Dixon Page 24 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.

Mark Dixon Page 25 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)