Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.

Slides:



Advertisements
Similar presentations
MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Advertisements

Files & Streams. Files Introduction Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.
Access Lesson 2 Creating a Database
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
1 Chapter 12 Working With Access 2000 on the Internet.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
The ADO Data Control. Universal Data Access Open Database Connectivity (ODBC) –standard for accessing data in databases OLE-DB –allows access to data.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Chapter 13: Advanced GUI and Graphics
Microsoft Visual Basic 2012 CHAPTER TEN Incorporating Databases with ADO.NET.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
1 Chapter 1 Tour of Access. 1 Chapter Objectives Start and exit Microsoft Access Open and run an Access application Identify the major elements of the.
Concepts of Database Management Sixth Edition
Chapter Extension 6 Using Microsoft Access © 2008 Pearson Prentice Hall, Experiencing MIS, David Kroenke.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
Chapter 15 - Creating More Complex Database Applications 1 Chapter 15 Creating More Complex Database Applications.
Access Tutorial 10 Automating Tasks with Macros
Chapter 2 Querying a Database
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
Access Lesson 2 Creating a Database
Unit J: Creating a Database Microsoft Office Illustrated Fundamentals.
Databases and LINQ Visual Basic 2010 How to Program 1.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
ASP.NET Programming with C# and SQL Server First Edition
Microsoft Visual Basic 2005: Reloaded Second Edition
XP Chapter 5 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Developing Effective Reports Chapter 5 “Nothing succeeds.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Analyzing Data For Effective Decision Making Chapter 3.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
Management Information Systems MS Access MS Access is an application software that facilitates us to create Database Management Systems (DBMS)
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Key Applications Module Lesson 21 — Access Essentials
MS Access 2007 Management Information Systems 1. Overview 2  What is MS Access?  Access Terminology  Access Window  Database Window  Create New Database.
Chapter 14 - Designing Data Access Classes1 Chapter 14 Designing Data Access Classes.
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
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.
XP Chapter 2 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Building The Database Chapter 2 “It is only the farmer.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
INTRODUCTION TO ACCESS. OBJECTIVES  Define the terms field, record, table, relational database, primary key, and foreign key  Create a blank database.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Session 1 Module 1: Introduction to Data Integrity
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Object-Oriented Application Development Using VB.NET 1 Chapter 2 The Visual Studio.NET Development Environment.
MSOffice Access Microsoft® Office 2010: Illustrated Introductory 1 Part 1 ® Database & Table.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Object-Oriented Application Development Using VB.NET 1 Chapter 11 Using Multiple Forms with Problem Domain Classes.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
1 Access Lesson 1 Understanding Access Fundamentals Microsoft Office 2010 Fundamentals Story / Walls.
Object-Oriented Application Development Using VB.NET 1 Chapter 15 Assembling a Three-Tier Windows Application.
Copyright © 2014 Pearson Canada Inc. Ext. 5b-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5b Using Microsoft Access Part 2: Using Information.
Visual Basic 2010 How to Program
IS444: Modern tools for applications development
IS444: Modern tools for applications development
Files & Streams.
Creating More Complex Database Applications
Unit J: Creating a Database
Presentation transcript:

Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence

Object-Oriented Application Development Using VB.NET 2 Objectives In this chapter, you will: Examine VB.NET input and output (I/O) Make objects persistent Design a data access class Communicate with a data access class Use a relational database with VB.NET

Object-Oriented Application Development Using VB.NET 3 Examining VB.NET Input and Output Stream –A collections of bytes that transfer data to and from files Stream classes with sequential file capabilities –StreamWriter Located in the System.IO namespace Derived from the TextWriter class –StreamReader Located in the System.IO namespace Derived from the TextReader class

Object-Oriented Application Development Using VB.NET 4 Examining VB.NET Input and Output In a file-based system –A file Represents the collection of all the data A file consists of records –A record Represents a single entity –A field An attribute that will be included for each record in the file A record consists of fields

Object-Oriented Application Development Using VB.NET 5 Sequential File Processing Sequential file processing example –Text boxes Allow users to enter values for each record to be saved to a sequential file Names of the text boxes –txtStRegNo –txtLength –txtManufacturer –txtYear –txtCustPhoneNo

Object-Oriented Application Development Using VB.NET 6 Sequential File Processing Sequential file processing example (continued) –Buttons Save To File button –Clicked to save the text box values to a sequential file List Records button –Clicked to extract the data from the file and display the results in a multiline text box with a vertical scroll bar Exit button –Closes the program

Object-Oriented Application Development Using VB.NET 7 Sequential File Processing

Object-Oriented Application Development Using VB.NET 8 General Format for StreamWriter and StreamReader The boat attribute file example –Uses the following methods of the StreamWriter class Write WriteLine Close –Uses the following methods of the StreamReader class Read ReadLine ReadToEnd Peek Close

Object-Oriented Application Development Using VB.NET 9 General Format for StreamWriter and StreamReader

Object-Oriented Application Development Using VB.NET 10 Adding Toolbars and Dialog Controls Dialog boxes and toolbars –Used to build professional user interfaces To incorporate a toolbar with graphic buttons on a form –Place the graphic images into the ImageList control –Add the toolbar control to the form –Link the toolbar’s ImageList property to the ImageList

Object-Oriented Application Development Using VB.NET 11 Adding Toolbars and Dialog Controls

Object-Oriented Application Development Using VB.NET 12 Adding Toolbars and Dialog Controls ImageList control –Images property A collection of images Used to open the Image Collection Editor –Image Collection Editor is used to »Add an image to the collection »Change the order in which the images are displayed »Delete images from the collection

Object-Oriented Application Development Using VB.NET 13 Adding Toolbars and Dialog Controls

Object-Oriented Application Development Using VB.NET 14 Adding Toolbars and Dialog Controls

Object-Oriented Application Development Using VB.NET 15 Adding Toolbars and Dialog Controls Toolbar control –ImageList property Used to link to the ImageList that holds the images

Object-Oriented Application Development Using VB.NET 16 Adding Toolbars and Dialog Controls Toolbar control –Buttons property Used to open the ToolBarButton Collection Editor –ToolBarButton Collection Editor can be used to »Add buttons to the toolbar

Object-Oriented Application Development Using VB.NET 17 Adding Toolbars and Dialog Controls

Object-Oriented Application Development Using VB.NET 18 Adding Dialogs to the Application Dialog boxes –Provide richness and standardization for common user interface operations –For example Functions which should have a common look and feel, regardless of the application –Opening and saving files –Changing colors –Changing fonts –To add a dialog box to an application Double-click the dialog control in the Toolbox

Object-Oriented Application Development Using VB.NET 19 The Save File Dialog Box SaveFile dialog box opens a file for saving

Object-Oriented Application Development Using VB.NET 20 OpenFile Dialog Box OpenFile dialog box opens a file for reading

Object-Oriented Application Development Using VB.NET 21 Adding the Color Dialog Box Color dialog box is used to change the color in applications

Object-Oriented Application Development Using VB.NET 22 The FontDialog Box FontDialog control –Used to change fonts and font colors in applications –Sets the Font property for controls

Object-Oriented Application Development Using VB.NET 23 Making Objects Persistent Object persistence –The capacity to store and retrieve information from files Two approaches to achieving persistence –Attribute storage –Object storage

Object-Oriented Application Development Using VB.NET 24 Making Objects Persistent Attribute storage –Involves Retrieving attribute values from the instance Writing attribute values to a file –Disadvantage It is necessary to re-create the object

Object-Oriented Application Development Using VB.NET 25 Making Objects Persistent

Object-Oriented Application Development Using VB.NET 26 Making Objects Persistent Options for storing and retrieving objects: –Attribute storage and retrieval using the StreamWriter and StreamReader –Object serialization –Attribute storage and retrieval using databases

Object-Oriented Application Development Using VB.NET 27 Making Objects Persistent Object serialization –An easy way to store and retrieve objects –Serialization process Transforms an object into a stream that can be saved to a sequential file –Deserialization Transforms the stream from the file back to the object state before the object was stored –Advantage The object can be retrieved intact It is not necessary to re-create the object

Object-Oriented Application Development Using VB.NET 28 Making Objects Persistent Databases –One or more files organized to help make queries –Can be used to make objects persistent –Organize data into tables that can be related to each other Each table column represents an attribute Each row represents a record –Structured Query Language (SQL) A standard set of keywords and statements used to access relational databases

Object-Oriented Application Development Using VB.NET 29 Designing a Data Access Class Purpose of a DA class –To provide methods that store and retrieve data –Make instances of a PD class persistent Reasons for placing data storage and retrieval tasks in a DA class –Data input and output code are isolated from other classes Can dramatically reduce maintenance –Separate classes for each tier make deployment easier in a client-server environment GUI, PD, and DA functions may reside on multiple machines at various sites

Object-Oriented Application Development Using VB.NET 30 Designing a Data Access Class DA methods can be invoked only by the PD class –Services provided by the DA class appear to be provided by the PD class –Hides the DA class from all other classes

Object-Oriented Application Development Using VB.NET 31 Data Access Methods A separate DA class is written for each PD class Example: –CustomerDA Provides data storage and retrieval services for customers Methods can only be invoked by the PD class

Object-Oriented Application Development Using VB.NET 32 Data Access Methods Four basic tasks provided by CustomerDA and Customer: –Retrieve a customer –Store a customer –Change a customer’s data –Remove a customer

Object-Oriented Application Development Using VB.NET 33 Data Access Methods CustomerDA class –Find method Functionality implemented: retrieve a customer –AddNew method Functionality implemented: store a customer –Update method Functionality implemented: update a customer’s data –Delete method Functionality implemented: remove a customer

Object-Oriented Application Development Using VB.NET 34 Data Access Methods CustomerDA class (continued) –Additional methods Initialize Terminate GetAll –Exception handler classes NotFoundException DuplicateException

Object-Oriented Application Development Using VB.NET 35 Communicating with a Data Access Class Customer class –Invokes methods in CustomerDA –Methods Find AddNew Find Delete Initialize Terminate GetAll

Object-Oriented Application Development Using VB.NET 36 Finding a Customer The PD Find method –Invokes the DA Find method Public Shared Function Find(ByVal PhoneNo As String) As Customer Return CustomerDA.Find(PhoneNo) End Function

Object-Oriented Application Development Using VB.NET 37 Adding a Customer The PD AddNew method –Invokes the AddNew method in the DA class to store a new customer instance Public Sub AddNew() CustomerDA.AddNew(Me) End Sub

Object-Oriented Application Development Using VB.NET 38 Changing a Customer The PD Update method –Invokes the Update method in the DA class Public Sub Update() CustomerDA.Update(Me) End Sub

Object-Oriented Application Development Using VB.NET 39 Deleting a Customer The PD Delete method –Invokes the Delete method in the DA class Public Sub Delete() CustomerDA.Delete(Me) End Sub

Object-Oriented Application Development Using VB.NET 40 Additional Problem Domain Methods Additional PD methods –Initialize Public Shared Sub Initialize() CustomerDA.Initialize() End Sub –Terminate Public Shared Sub Terminate() CustomerDA.Terminate() End Sub

Object-Oriented Application Development Using VB.NET 41 Additional Problem Domain Methods Additional PD methods (continued) –GetAll Public Shared Function GetAll() As ArrayList Return CustomerDA.GetAll End Function

Object-Oriented Application Development Using VB.NET 42 Implementing Persistence with a Sequential File Attribute storage –Used for sequential access files The Initialize method –Reads customer’s attribute values from the sequential file –Creates customer instances –Stores references for these instances in an ArrayList

Object-Oriented Application Development Using VB.NET 43 Implementing Persistence with a Sequential File Terminate method –Creates a file that Contains attribute values for all the customer instances referenced by the ArrayList customers Find method –Seeks a customer instance with a phone number that matches the value received by the method If the customer is found –Its reference is returned If the customer is not found –A NotFoundException is thrown

Object-Oriented Application Development Using VB.NET 44 Implementing Persistence with a Sequential File AddNew method –Adds the new reference to the ArrayList after checking for a duplicate phone number A duplicate phone number is assumed to be a duplicate customer

Object-Oriented Application Development Using VB.NET 45 Implementing Persistence with a Sequential File Update method –Contains no code –Updates are made to the customer instance by invoking accessor methods setName setAddress setPhoneNo –Later Terminate method –Writes the attribute values for all the instances to a sequential file

Object-Oriented Application Development Using VB.NET 46 Implementing Persistence with a Sequential File Delete method –Removes a customer from the system by Removing the customer from the ArrayList customers –Later Terminate method –Saves all the customers in the ArrayList customers to the sequential file

Object-Oriented Application Development Using VB.NET 47 Implementing Persistence with a Sequential File GetAll method –Returns a reference to the customers ArrayList DuplicateException and NotFoundException classes –Inform the invoking client of a problem

Object-Oriented Application Development Using VB.NET 48 Testing CustomerDA for Sequential File Implementation The tester application will: –Create two customer instances –Invoke the Initialize method –Invoke the AddNew method to add the two new customers to storage –Retrieve a reference to the first customer by invoking the Find method

Object-Oriented Application Development Using VB.NET 49 Testing CustomerDA for Sequential File Implementation The tester application will (continued): –Invoke the GetAll method to retrieve references to both customers –Invoke the Delete method for the second customer and verify the deletion –Change the first customer’s address and verify the change using the Update method –Invoke the Terminate method

Object-Oriented Application Development Using VB.NET 50 Implementing Persistence with Object Serialization Persistence using object serialization –Uses object storage –Complete object instances are written to and read from a file –Instances are retrieved intact There is no need to re-create instances –Uses the FileStream class

Object-Oriented Application Development Using VB.NET 51 Implementing Persistence with Object Serialization To change from sequential access file processing to object serialization –Add the attribute to the Customer definition header –Change the following methods in CustomerDA Initialize Terminate

Object-Oriented Application Development Using VB.NET 52 Using Relational Databases with VB.NET Relational databases –Referred to as database management systems (DBMSs) –Provide tools for organizing data into tables In a DBMS –Each column represents a field –Each row represents a record –Primary key: a field used to uniquely identify a record

Object-Oriented Application Development Using VB.NET 53 Structured Query Language Structured Query Language (SQL) –A standardized language used to manage and query relational databases –Used by DA methods Find method uses the SQL SELECT statement to –Retrieve a specific customer’s record from the database AddNew method uses the SQL INSERT INTO statement to –Add a new customer’s record to the database

Object-Oriented Application Development Using VB.NET 54 Structured Query Language Uses of SQL by DA methods (continued) –Update method uses the SQL UPDATE statement to Change the contents of one or more fields in a customer’s record –Delete method executes the SQL DELETE statement SQL DELETE statement specifies the key value of the customer to be deleted

Object-Oriented Application Development Using VB.NET 55 Accessing a DBMS with VB.NET VB.NET options for accessing data –ADO (Active-X Data Objects) Maintains a constant connection to the server Data is kept and processed in a recordset –ADO.NET Only connects to the server when –Data is needed from the data store –Updates back to the data store are required Relies on the concept of datasets as the basis for processing data

Object-Oriented Application Development Using VB.NET 56 VB.NET Database Access Classes VB.NET managed providers for accessing data: –The OleDb data provider Designed for accessing Microsoft Access databases and other non-SQLServer data sources Namespace: OleDb –The SQLServer data provider Designed for accessing Microsoft SQLServer databases Namespace: SQLClient Object database connectivity (ODBC) –Can be used to access most other databases

Object-Oriented Application Development Using VB.NET 57 VB.NET Database Access Classes

Object-Oriented Application Development Using VB.NET 58 VB.NET and DBMS Example Example –Project involves working with data from a relational database Selecting, adding, updating, and deleting rows from a table –The GUI includes A data grid Four buttons –Add Record –Update Record –Delete Record –Find

Object-Oriented Application Development Using VB.NET 59 VB.NET and DBMS Example

Object-Oriented Application Development Using VB.NET 60 Implementing Object Persistence with a Database To implement object persistence with a relational database –Initialize method establishes a connection to the database –Find, AddNew, Update, Delete, and GetAll methods access the database directly –Terminate method closes the database connection

Object-Oriented Application Development Using VB.NET 61 Summary Object persistence: storing instance data for future retrieval Persistence can be achieved by storing either attribute values or entire instances A data access (DA) class provides methods that store and retrieve data Methods of a DA class are invoked only by the methods of the corresponding PD class Methods of a DA class: Find, AddNew, Update, Delete, GetAll, Initialize, and Terminate

Object-Oriented Application Development Using VB.NET 62 Summary VB.NET’s stream approach to I/O views data input and output as a flow of bytes Persistence can be achieved using sequential files, object serialization, or relational databases A relational database is used to organize data into tables In a relational database, each column represents a field and each row represents a record SQL is a popular, standard language used to access relational databases