Creating More Complex Database Applications

Slides:



Advertisements
Similar presentations
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Advertisements

Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
Object-Oriented Application Development Using VB.NET 1 Creating a String Array Code to create a String array: ' declare a String array with 4 elements.
Chapter 13: Advanced GUI and Graphics
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Object-Oriented Application Development Using VB.NET 1 Chapter 9 Implementing Association Relationships.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Mgt 20600: IT Management & Applications Databases Tuesday April 4, 2006.
Chapter 15 - Creating More Complex Database Applications 1 Chapter 15 Creating More Complex Database Applications.
Chapter 9 - Implementing Association Relationships1 Chapter 9 Implementing Association Relationships.
Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 13 Database Management Systems: Getting Data Together.
ASP.NET Programming with C# and SQL Server First Edition
Data-mining & Data As we used Excel that has capability to analyze data to find important information, the data-mining helps us to extract information.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
IE 423 – Design of Decision Support Systems Database development – Relationships and Queries.
Chapter 14 - Designing Data Access Classes1 Chapter 14 Designing Data Access Classes.
Chapter 12 - Designing Multiwindow Applications1 Chapter 12 Designing Multiwindow Applications 12.
Object-Oriented Application Development Using VB.NET 1 Chapter 6 Writing a Problem Domain Class Definition.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 7 (Part a): Introduction to SQL Modern Database Management 9 th Edition Jeffrey A.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
Database Management Supplement 1. 2 I. The Hierarchy of Data Database File (Entity, Table) Record (info for a specific entity, Row) Field (Attribute,
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload.
Session 1 Module 1: Introduction to Data Integrity
* Database is a group of related objects * Objects can be Tables, Forms, Queries or Reports * All data reside in Tables * A Row in a Table is a record.
Object-Oriented Application Development Using VB.NET 1 Chapter 9 Implementing Association Relationships.
Chapter 3: Relational Databases
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Object-Oriented Application Development Using VB.NET 1 Chapter 11 Using Multiple Forms with Problem Domain Classes.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
Object-Oriented Application Development Using VB.NET 1 Chapter 15 Assembling a Three-Tier Windows Application.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Chapter 5 Database Design
Chapter 4 Logical Database Design and the Relational Model
Chapter 4: Logical Database Design and the Relational Model
Relational Model.
Databases Chapter 16.
© 2016, Mike Murach & Associates, Inc.
Information Systems Today: Managing in the Digital World
Objectives Query for top values Create a parameter query
IS444: Modern tools for applications development
Relational Databases.
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
LINQ to DATABASE-2.
CSCI-100 Introduction to Computing
Chapter 4 Relational Databases
IS444: Modern tools for applications development
Databases and Information Management
VB.NET Using Database.
The University of Texas – Pan American
Chapter 8 Working with Databases and MySQL
Database Fundamentals
5.02 Understand database queries, forms, and reports used in business.
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Access: SQL Participation Project
Data Model.
Databases and Information Management
Relational Database Design
logical design for relational database
Chapter 17 Designing Databases
Databases Continued 10/18/05.
Manipulating Data Lesson 3.
Microsoft Access Date.
Unit – V Data Controls.
Presentation transcript:

Creating More Complex Database Applications Chapter 14 Creating More Complex Database Applications Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Objectives In this chapter, you will: Implement a one-to-one association in a database application Implement a one-to-many association in a database application Apply parent-child (hierarchical) dataset relationships Implement an association class in a database application Object-Oriented Application Development Using VB .NET

Implementing a One-to-One Association in a Database Application Relationships between Customer and Boat Mandatory One-to-one relationships in both directions A customer always owns exactly one boat A boat is always owned by exactly one customer Object-Oriented Application Development Using VB .NET

Implementing a One-to-One Association in a Database Application Object-Oriented Application Development Using VB .NET

Understanding the CustomerAndBoat Database Tables of CustomerAndBoatDatabase BoatTable CustomerTable Object-Oriented Application Development Using VB .NET

Understanding the CustomerAndBoat Database BoatTable fields StateRegistrationNo BoatLength Manufacturer Year CustomerPhoneNo Object-Oriented Application Development Using VB .NET

Understanding the CustomerAndBoat Database CustomerTable fields Name Address PhoneNo Object-Oriented Application Development Using VB .NET

Understanding the CustomerAndBoat Database Primary key A field that uniquely identifies each record in a relational database table CustomerTable primary key: PhoneNo BoatTable primary key: StateRegistrationNo Foreign key A field in one table that serves as a primary key in a related table BoatTable foreign key: CustomerPhoneNo Object-Oriented Application Development Using VB .NET

Understanding the CustomerAndBoat Database Object-Oriented Application Development Using VB .NET

Using SQL to Join Tables in the Database Joining two tables in SQL Using foreign and primary keys to link information in one table to information in another table Example Find and display the state registration number and manufacturer of all boats in BoatTable, with the name, address, and phone number of each boat’s owner SELECT StateRegistrationNo, Manufacturer, Name, Address, PhoneNo FROM BoatTable, CustomerTable WHERE CustomerPhoneNo = PhoneNo Object-Oriented Application Development Using VB .NET

Using SQL to Join Tables in the Database Example: Display the name and address of the owner of the boat with state registration number MO98765 SELECT StateRegistrationNo, Name, Address FROM BoatTable, CustomerTable WHERE CustomerPhoneNo = PhoneNo AND StateRegistrationNo = 'MO98765'   Object-Oriented Application Development Using VB .NET

Establishing a Common Connection to the Database CustomerAndBoatDatabaseConnect program Establishes a common connection to CustomerAndBoatDatabase Used by CustomerDA BoatDA Object-Oriented Application Development Using VB .NET

Modifying the Customer Class Additions to Customer class to reflect the link between CustomerTable and BoatTable A boat reference attribute Enables a customer instance to know about its associated boat instance Initialized to Nothing in the constructor A setter method to set the boat reference attribute A getter method to retrieve the boat reference attribute Object-Oriented Application Development Using VB .NET

Introducing the BoatDA Class Needed because the CustomerAndBoatDatabase application must Find Add Delete Update records in BoatTable Object-Oriented Application Development Using VB .NET

Introducing the BoatDA Class Methods of BoatDA class Initialize Opens a connection to the database Terminate Closes the connection to the database Find Defines an SQL SELECT statement that retrieves a particular record from BoatTable Object-Oriented Application Development Using VB .NET

Introducing the BoatDA Class Methods of BoatDA class (continued) GetAll Similar to the Find method, but returns an ArrayList of boat references AddNew Uses the SQL INSERT INTO clause to insert the information for a new boat into BoatTable Update Used to change the value of a field or fields of a boat Delete Deletes a boat record from the table Object-Oriented Application Development Using VB .NET

Modifying the Boat Class to Work With BoatDA Additions to the Boat class needed to work with the BoatDA class Four shared methods to invoke the following methods of BoatDA Initialize Find GetAll Terminate Object-Oriented Application Development Using VB .NET

Modifying the Boat Class to Work With BoatDA Additions to the Boat class needed to work with the BoatDA class (continued) Three instance methods to invoke the following methods of BoatDA AddNew Update Delete Revision of the TellAboutSelf method To improve readability of the information returned to the calling program Object-Oriented Application Development Using VB .NET

Modifying the CustomerDA Class Modifications in CustomerDA Needed to support joining the information from BoatTable and CustomerTable A boat reference variable and variables to represent boat attributes Find method Extended to retrieve data from both tables Object-Oriented Application Development Using VB .NET

Modifying the CustomerDA Class Modifications in CustomerDA (continued) AddNew method When a customer record is inserted Invokes the AddNew method of the BoatDA class to insert the associated boat record into BoatTable Delete method When a customer record is deleted The corresponding boat record is also deleted Object-Oriented Application Development Using VB .NET

Implementing a One-to-Many Association in a Database Application The relationship between Dock and Slip A one-to-many relationship A dock contains many slips A slip belongs to exactly one dock Object-Oriented Application Development Using VB .NET

Understanding the Tables in DockAndSlipDatabase Tables of the DockAndSlipDatabase DockTable SlipTable Columns of DockTable DockId (the primary key) Location Electricity Water Object-Oriented Application Development Using VB .NET

Understanding the Tables in DockAndSlipDatabase Columns of SlipTable SlipNo DockId Width SlipLength BoatId Object-Oriented Application Development Using VB .NET

Understanding the Tables in DockAndSlipDatabase SlipNo and DockId Together uniquely identify a slip Form a concatenated key Concatenated key: a key that contains more than one field (or column) in the database Object-Oriented Application Development Using VB .NET

Understanding the Tables in DockAndSlipDatabase DockId in SlipTable is a foreign key to information in DockTable Object-Oriented Application Development Using VB .NET

Establishing a Common Connection to DockAndSlipDatabase DockAndSlipDatabaseConnect program Establishes a single connection to DockAndSlipDatabase Shared by the PD and DA classes that require access to the database Identical to CustomerAndBoatDatabaseConnect, except for the specified data source name Object-Oriented Application Development Using VB .NET

Modifying the Dock and Slip Classes The Dock class (now called mDock) Modifications to the Dock class Class name changed to mDock To eliminate conflict with VB .NET’s Dock class (used for Windows forms) Addition of the System.Data.OleDb namespace Addition of a TellAboutSelf method Does not currently require methods to Insert records Update records Delete records Object-Oriented Application Development Using VB .NET

Modifying the Dock and Slip Classes No need to modify the Slip class Already includes the code to associate a slip with its dock Does not need Insert method Delete method Update method Does not need Find and GetAll methods of its own A SlipDA class is not needed for the DockAndSlipDatabase application Object-Oriented Application Development Using VB .NET

Introducing the DockDA Class Used to access information in DockTable Does not require the following methods Insert Delete Update Find method Defines the SQL SELECT statement needed to extract dock and slip information from the database Object-Oriented Application Development Using VB .NET

Introducing the DockDA Class DockDA class (continued) GetAll method The SQL query returns dock and slip information for all docks and slips in the marina, sorted in order by dock and then by slip Uses control-break logic A control-break occurs when there is a change in the value of a variable that is used to group a list of sorted items Object-Oriented Application Development Using VB .NET

Applying Parent-Child (Hierarchical) Dataset Relationships An application is best represented by a hierarchical, or parent-child, relationship of tables The dock and slip relationship can be a parent-child relationship A dock can have many slips Each slip must be associated with only one dock Object-Oriented Application Development Using VB .NET

Applying Parent-Child (Hierarchical) Dataset Relationships Processing logic for a parent-child relationship between DockTable and SlipTable For each row of DockTable Iterate over SlipTable finding all the slips that belonged to the corresponding dock Object-Oriented Application Development Using VB .NET

Applying Parent-Child (Hierarchical) Dataset Relationships Object-Oriented Application Development Using VB .NET

Applying Parent-Child (Hierarchical) Dataset Relationships VB .NET datasets provide the functionality of establishing parent-child relationships of the tables in a dataset For example: GetAll method of the DockDA class can be rewritten using a parent-child relationship of a dataset Object-Oriented Application Development Using VB .NET

Understanding the Tables in CustomerLeaseSlipDatabase Database tables of the application CustomerTable LeaseTable SlipTable Object-Oriented Application Development Using VB .NET

Understanding the Tables in CustomerLeaseSlipDatabase Object-Oriented Application Development Using VB .NET

Understanding the Tables in CustomerLeaseSlipDatabase LeaseTable Customer phone number: a foreign key to link to CustomerTable A customer’s phone number Used as the primary key for LeaseTable (CustomerPhoneNo) Used as the primary key for CustomerTable (PhoneNo) Columns for slip number and dock ID serve as a concatenated foreign key to records in SlipTable Object-Oriented Application Development Using VB .NET

Understanding the Tables in CustomerLeaseSlipDatabase Object-Oriented Application Development Using VB .NET

Understanding the Tables in CustomerLeaseSlipDatabase CustomerLeaseSlip application has Four problem domain classes Customer Slip Lease AnnualLease Three data access classes CustomerDA SlipDA LeaseDA A test class A class to establish a connection to the database Object-Oriented Application Development Using VB .NET

Establishing a Connection to CustomerLeaseSlipDatabase CustomerLeaseSlipConnect program Establishes a single connection to CustomerLeaseSlipDatabase Shared by the PD and DA classes involved in this application Identical to the other connect programs, except for the specified data source name Object-Oriented Application Development Using VB .NET

Modifying the Customer Class Modifications needed in the Customer PD class A lease reference of the AnnualLease type Initialized to nothing by the constructor A setter method to set the AnnualLease reference variable A getter method to retrieve the AnnualLease reference variable Object-Oriented Application Development Using VB .NET

Modifying the Lease and AnnualLease Classes Must associate a lease with its customers and slips Additions needed to accomplish this A slip reference variable Initially set to Nothing in the constructor A customer reference variable Getter methods to retrieve the slip and customer variables Setter methods to set the slip and customer variables Object-Oriented Application Development Using VB .NET

Modifying the Lease and AnnualLease Classes Additions to the AnnualLease subclass Initialize method Terminate method Find method AddNew method Object-Oriented Application Development Using VB .NET

Modifying the Slip Class Must associate a slip with its corresponding lease and customer Additions needed to accomplish this An AnnualLease reference Initially set to Nothing in the constructor Initialize method Terminate method Find method Object-Oriented Application Development Using VB .NET

Modifying the Slip Class Additions needed to associate a slip with its corresponding lease and customer (continued) LeaseAnnualSlip method Associates the slip with its corresponding lease instance Object-Oriented Application Development Using VB .NET

Introducing the SlipDA Class Needed in the CustomerLeaseSlip application Contains Variables for Slip attributes Establishing the database connection Initialize method Identical to those in the other DA classes Object-Oriented Application Development Using VB .NET

Introducing the SlipDA Class SlipDA class (continued) Terminate method Identical to those in the other DA classes Find method Defines a SQL SELECT statement that returns information from SlipTable for a particular slip Object-Oriented Application Development Using VB .NET

Introducing the AnnualLeaseDA Class Needed in the CustomerLeaseSlip application Information about annual leases must be found and inserted in the database Contains Variables for AnnualLease attributes Initialize method Terminate method Object-Oriented Application Development Using VB .NET

Introducing the AnnualLeaseDA Class AnnualLeaseDA class contains (continued) Find method Requires an SQL query that retrieves data from CustomerTable, LeaseTable, and SlipTable AddNew method Adds a lease record to the database Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Summary A primary key is an attribute (or combination of attributes) that uniquely identifies a single record in a relational database table A foreign key is an attribute (or column) in one relational database table that serves as a primary key in a different (or foreign) table A concatenated key (primary or foreign) is one that consists of more than one attribute (or column) in the database table Object-Oriented Application Development Using VB .NET

Object-Oriented Application Development Using VB .NET Summary When multiple tables are involved, DA Insert and Delete methods must incorporate measures to preserve the integrity of the database A control-break occurs when there is a change in the value of a variable that is used to group a list of sorted items VB .NET datasets provide the functionality to visualize and process data hierarchically, referred to as a parent-child relationship Object-Oriented Application Development Using VB .NET