Mark Dixon, SoCCE SOFT 131Page 1 17 – Persistent data storage: relational databases and ADO.

Slides:



Advertisements
Similar presentations
Basics of Database Programming with VB6
Advertisements

ADO DB in Access VBA © Walter Milner 2005 Slide: 1 ADO VBA Programming in Access.
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.
ActiveX Data Object ISYS 562. ADO An ActiveX control ActiveX is build upon COM, a contract that defines a standard interface by which objects communicate.
Informatiesystemen in de Bouw 7M711 Joran Jessurun en Jos van Leeuwen Week 3.
Mark Dixon Page 1 SOFT – Module Introduction.
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.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)
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, SoCCE SOFT 131Page 1 19 – Web applications: Server-side code (ASP)
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 8 Relational Databases ActiveX Database Controls 8 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
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.
Unit 18: Database Modelling
Introduction to ADO By David R. Stevenson Consulting Software Engineer ABB Automation.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 11 Accessing Database.
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.
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.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
Lecture Note 10: Simple Database Techniques. Introduction –Database System –Access, SQL Server and others. –Microsoft Access - Interacting with this databases.
Visual Basic ADO Programming 56:150 Information System Design.
What is database?  Any Method for access info into Application from DataBase?  ODBC is standard for Accessing Data.  Problem with ODBC:  Information.
How to Connect to Database ODBC (Open Database Connectivity) ADO (ActiveX Data Object) ASP Code To Connect to Database Recordset Object Navigating through.
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.
Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information.
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.
Mark Dixon 1 21 – Databases: Multiple Tables and Writing Data.
Lesson 2: Designing a Database and Creating Tables.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Web applications: Databases & ASP.
Lab 8 Data Access Using Microsoft ActiveX Data Object (ADO)
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.
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.
Using a Database Access97 Please use speaker notes for additional information!
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
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.
 2 Data Object Library approaches ◦ DAO (Data Access Objects)  Original access strategy (up to VB6)  Closely linked to MS Access ◦ ADO (ActiveX Data.
Introduction to Database Programming with Python Gary Stewart
ADO VBA Programming in Access
Find, filter etc with connection to Access code internally
18 – Databases: Structured Query Language
VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY.
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, SoCCE SOFT 131Page 1 17 – Persistent data storage: relational databases and ADO

Mark Dixon, SoCCE SOFT 131Page 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 –use a relational database to store an application's data between executions –create an entity-relationship diagram from a database

Mark Dixon, SoCCE SOFT 131Page 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, SoCCE SOFT 131Page 4 Record Field Flat files: Data Duplication 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, SoCCE SOFT 131Page 5 Relations (tables) Track TitleArtist ID Paranoid1 Falling in Love2 Pink2 Love in an Elevator2 Smooth Criminal3 Meaning of Life4 The Game4 Voices4 Down with the Sickness4 Artist ID Artist NameCountry 1Black SabbathUK 2AerosmithUS 3Alien Ant FarmUS 4DisturbedUS Track Artist Primary Key Foreign Key

Mark Dixon, SoCCE SOFT 131Page 6 Normalisation Part of database design Process of breaking data down Codd –7 stages of normalisation Mathematical Difficult to apply stages

Mark Dixon, SoCCE SOFT 131Page 7 Exercise: Prescriptions Identify duplication and separate: DateSurnameForenamesDrug Name 6 Jan 04JonesAlisonCo-codamol 11 Jan 04SmithBobTegretol 18 Jan 04HopeJohnCo-codamol 5 Feb 04JohnsonSallyCo-codamol 8 Feb 04SmithBobTegretol 10 Feb 04SmithBobSorbitol Prescription

Mark Dixon, SoCCE SOFT 131Page 8 Exercise: Solution DatePatientIDDrugID 6 Jan Jan Jan Feb Feb Feb 0423 Prescription PatientIDSurnameForenames 1JonesAlison 2SmithBob 3HopeJohn 4JohnsonSally Patient DrugIDDrug Name 1Co-codamol 2Tegretol 3Sorbitol Drug

Mark Dixon, SoCCE SOFT 131Page 9 People Database (with Hobbies) IDSurnameForenamesPhone 1DixonMark SmithJohn JonesSally BloggsFred AndersonGenny01752 HobbyIDDescriptionPersonID 1Archery1 2Herpetology1 3Music1 4Football2 5Rugby2 6Hitting people with swords1 Hobby Person

Mark Dixon, SoCCE SOFT 131Page 10 Entity-relationship diagrams Each table in db –stores details of entity shown as rectangular box Relationships between tables –represent relationships between entities shown as line between entities (boxes) PersonHobby

Mark Dixon, SoCCE SOFT 131Page 11 Relationship Types One-to-one One-to-many Many-to-one Many-to-many –(can't be implemented in relational database) ABABABAB

Mark Dixon, SoCCE SOFT 131Page 12 Exercise: Which relationship type? IDSurnameForenamesPhone 1DixonMark SmithJohn JonesSally BloggsFred AndersonGenny01752 HobbyIDDescriptionPersonID 1Archery1 2Herpetology1 3Music1 4Football2 5Rugby2 6Hitting people with swords1 Hobby Person Hobby

Mark Dixon, SoCCE SOFT 131Page 13 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, SoCCE SOFT 131Page 14 MS Access Music database

Mark Dixon, SoCCE SOFT 131Page 15 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, SoCCE SOFT 131Page 16 Enabling ADO Project menu –References item Microsoft ActiveX Data Objects Library (latest 2.7)

Mark Dixon, SoCCE SOFT 131Page 17 ADO RecordSet Object Used to interact with tables Properties –BOF: true if at start of recordset (before first record) –EOF: true if at end of recordset (after last record) –Fields: used to get and set data values Methods –Open: used to open recordset –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 recordset

Mark Dixon, SoCCE SOFT 131Page 18 Example: Music Private Sub btnLoad_Click() Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset rs. Open "Track", cs rs. MoveFirst Do Until rs. EOF lstTracks.AddItem rs.Fields("TrackTitle").Value rs. MoveNext Loop rs. Close Set rs = Nothing End Sub btnLoadlstTracks

Mark Dixon, SoCCE SOFT 131Page 19 Connection Strings Connection string – identify data source Const cs = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=D:\Music.mdb;" & _ "Persist Security Info=False" Private Sub btnLoad_Click() Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset rs.Open "Track", cs … End Sub

Mark Dixon, SoCCE SOFT 131Page 20 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, SoCCE SOFT 131Page 21 Searching for Data Recordset methods –Find: searches for the next record to match given criteria string: e.g. "Name = 'Smith' " ( " are for VB string) ( ' are for database string)

Mark Dixon, SoCCE SOFT 131Page 22 Example: Music v2 Private Sub lstTracks_Click() Dim rs As ADODB.Recordset Dim strCriteria As String Set rs = New ADODB.Recordset rs.Open "Track", cs, adOpenDynamic strCriteria = "TrackTitle = '" & _ lstTracks.List(lstTracks.ListIndex) & "'" rs. Find strCriteria txtTrackTitle.Text = rs.Fields("TrackTitle").Value rs.Close Set rs = Nothing End Sub

Mark Dixon, SoCCE SOFT 131Page 23 Changing Data Recordset methods –AddNew: inserts a new record and makes it current –Update: sends changes back to DB –Delete: deletes currently selected record

Mark Dixon, SoCCE SOFT 131Page 24 Example: Music v3 Private Sub txtTrackTitle_Change() Dim rs As ADODB.Recordset Dim strCriteria As String Set rs = New ADODB.Recordset rs.Open "Track", cs, adOpenDynamic, adLockPessimistic strCriteria = "TrackTitle = '" & _ lstTracks.List(lstTracks.ListIndex) & "'" rs.Find strCriteria rs.Fields("TrackTitle").Value = txtTrackTitle.Text rs.Update rs.Close Set rs = Nothing End Sub