vb6 db manual

Download VB6 DB Manual

Post on 01-Dec-2015

58 views

Category:

Documents

8 download

Embed Size (px)

TRANSCRIPT

  • Visual Basic and Databases

    LAP II ISPGAYA

  • Visual Basic and Databases

    LAP II

    ii

    Notice

    This guide was developed for the course, Visual Basic and Databases,. It is not intended to be a complete reference to Visual Basic. Consult the Microsoft documentation that comes with your particular version of Visual Basic for detailed reference information. This guide refers to several software and hardware products by their trade names. These references are for informational purposes only and all trademarks are the property of their respective companies.

  • Contents

    LAP II

    iii

    Visual Basic and Databases

    Contents

    1. Introducing Visual Basic and Databases Preview ......................................................................................................1-1 Course Objectives......................................................................................1-2 Course Requirements ................................................................................1-3 What is a Database?..................................................................................1-4 Where Does Visual Basic Fit In?................................................................1-6 Building a Visual Basic Application ............................................................1-8 Structure of a Visual Basic Application .................................................1-8 Steps in Developing Application ...........................................................1-9 Drawing the User Interface and Setting Properties...............................1-9 Setting Properties of Controls at Design Time....................................1-13 Setting Properties at Run-Time ..........................................................1-14 How Names are Used in Object Events .............................................1-14 Writing Code ............................................................................................1-15 Review of Variables............................................................................1-15 Visual Basic Data Types.....................................................................1-15 Variable Declaration ...........................................................................1-16 Example 1. Mailing List Application..........................................................1-18 Summary .................................................................................................1-25 2. Introduction to Databases Review and Preview ..................................................................................2-1 Database Structure and Terminology ........................................................2-2 Relational Databases.................................................................................2-3 Sample Relational Database......................................................................2-4 Sample Database Structure.......................................................................2-7 Virtual Database Tables.............................................................................2-8 Creating a Database ................................................................................2-10 Summary .................................................................................................2-11

  • Visual Basic and Databases

    LAP II

    iv

    3. Database Connection with the DAO Data Control Review and Preview ..................................................................................3-1 DAO or ADO Whats the Difference? ......................................................3-2 DAO Data Control ......................................................................................3-3 DAO Data Control Properties ...............................................................3-4 Recordset Object..................................................................................3-5 Data Bound Controls..................................................................................3-6 Data Bound Control Properties.............................................................3-6 Example 3-1. Accessing the Books Database ...........................................3-8 DAO Data Control Events ........................................................................3-11 DAO Data Control Methods .....................................................................3-11 DAO Data Control Recordset Properties .................................................3-12 DAO Data Control Recordset Methods ....................................................3-13 DAO Data Control Recordset Navigation.................................................3-14 Quick Example 1 - Recordset Navigation ...........................................3-15 Summary .................................................................................................3-17 Exercise 3. Northwind Traders Database ................................................3-18

  • Contents

    LAP II

    v

    4. Database Connection with ADO Technology Review and Preview ..................................................................................4-1 ADO Data Control ......................................................................................4-2 ADO Data Control Properties ...............................................................4-3 ConnectionString Property....................................................................4-4 Recordset Object..................................................................................4-5 Data Bound Controls..................................................................................4-6 Data Bound Control Properties.............................................................4-6 Example 4-1. Accessing the Books Database ...........................................4-8 ADO Data Control Events ........................................................................4-11 ADO Data Control Methods .....................................................................4-12 ADO Data Control Recordset Properties .................................................4-12 ADO Data Control Recordset Methods ....................................................4-13 ADO Data Control Recordset Navigation.................................................4-14 Quick Example 1 - Recordset Navigation ...........................................4-15 DAO or ADO Whats the Difference? ....................................................4-17 ADO Data Environment ...........................................................................4-18 Connection Object ..............................................................................4-19 Command Object................................................................................4-19 Quick Example 2 Use of ADO Data Environment............................4-20 Data Bound Controls with the Data Environment.....................................4-23 Example 4-2. Drag and Drop Controls................................................4-24 Recordsets in the Data Environment .......................................................4-27 Quick Example 3 Record Navigation with the Data Environment ....4-28 DAO to ADO ADO to DAO....................................................................4-30 Summary .................................................................................................4-32 Exercise 4-1. Northwind Traders Database .............................................4-33 Exercise 4-2. Data Environment with Northwind Traders Database ........4-36

  • Visual Basic and Databases

    LAP II

    vi

    5. Database Queries with SQL Review and Preview ..................................................................................5-1 SQL Background........................................................................................5-2 Basics of SQL ............................................................................................5-3 Where Does SQL Fit In Visual Basic? .......................................................5-5 SQL with the DAO Data Control.................................................................5-6 Quick Example 1 - SQL with the DAO Data Control .............................5-7 SQL with the ADO Data Control.................................................................5-9 Quick Example 2 - SQL with the ADO Data Control ..........................5-10 SQL with the ADO Data Environment ......................................................5-12 Quick Example 3 - SQL with the ADO Data Environment ..................5-14 Example 5-1. SQL Tester ........................................................................5-17 A Brief (Hopefully) Interlude for Visual Basic 6 Users ..............................5-18 SELECT/FROM SQL Statement ..............................................................5-23 ORDER BY Clause ..................................................................................5-25 WHERE Clause .......................................................................................5-28 Single Table WHERE Clause...................................................................5-29 Multiple Table WHERE Clause ................................................................5-32 INNER JOIN Clause ................................................................................5-37 OUTER JOIN Clause ...............................................................................5-41 Visual Basic Functions with SQL .............................................................5-43 SQL Aggregate Functions........................................................................5-45 S