Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 7 Database Basics Tables, Records, and Fields 7 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.

Similar presentations


Presentation on theme: "Chapter 7 Database Basics Tables, Records, and Fields 7 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton."— Presentation transcript:

1

2 Chapter 7 Database Basics Tables, Records, and Fields 7 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton

3 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.2 Objectives 1. Explain the differences between a flat-file database and a relational database. 2. Explain the basic terminology for databases such as table, record and field. 3. Implement a flat-file database using random access. 4. Explain the use of the Microsoft FlexGril control.

4 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.3 Database Concepts... Database - collection of data for a particular purpose that is stored and later retrieved Flat-file database - database that is stored in a single table Relational database - database that is stored in multiple tables and cross- referenced

5 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.4 Database Concepts Field - the smallest unit of data (or fact) in a database Record - consists of several fields; stores data about a single entity in a database such as a client, product, student Table - represents data where each row represents a record, and each column represents a field

6 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.5 The Type statement...  Create records by defining a new data type  Use the Type statement to define and create a new data type Example: Type Person Firstname As String * 25 Lastname As String * 50 Birthdate As String * 35 City As String * 25 State As String * 2 End Type

7 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.6 The Type statement Type variablename elementname1 As datatype elementname2 As datatype... End Type Where variablename is a programmer-named variable elementname is a programmer-named element (or field) contained within the new type datatype is a Visual Basic data type such as Integer, Currency, String etc.

8 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.7 Declaring a New Data Type Public variablename As Typename Where variablename is a programmer named variable typename is a programmer named data type as defined with a type statement Example: Public CurrentRecord As Person

9 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.8 Birthday Database Create a flat-file database. Store the records in binary file format, and use random access. Notice the 7 fields in the displayed record.

10 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.9 Birthday Database Hands-On Exercise 1 Create a new project Set properties and add code for the Splash form Add code and test the module Create the Main form Add record declarations and code to the module Add more code and test the start procedure

11 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.10 Navigating the Database... Variables in the Birthday database CurrentRecord - stores current record data NewRecord - flag that indicates if the record needs to be written to the database file RecordNumber - the number of the current record MaxNumber - the number of records in the database OldRecordNumber - previous record number displayed in form

12 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.11 Navigating the Database... Procedures in the Birthday Database Main - opens the database file, and displays the Splash form Start - displays the Main form AddRecord - adds a new record DeleteRecord - deletes a record SaveRecord - writes a record to the file DisplayRecord - reads a record and displays it in the Main form ExitApplication - closes file, unloads form, exits

13 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.12 Navigating the Database Move Last Move Next Caption Move Previous Move First cmdLast cmdNext lblNumber cmdPrevious cmdFirst

14 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.13 Continue the Birthday Database Hands-On Exercise 2 Add code for AddRecord, DisplayRecord, SaveRecord, and ExitApplication procedures Add code to load & unload the Main form Add code for Add and Save Record buttons Test Start procedure and code for a new database Add first and last record and exit Add code and test first, last, next and previous buttons Test navigation buttons Test and add more records Exit the application

15 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.14 The Microsoft FlexGrid Control  Specially designed to display tables or grids of data  Use to sort, merge, and format tables  Add to Toolbox first

16 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.15 FlexGrid Properties FlexGrid control has over 100 different properties

17 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.16 Finish the Birthday Database Hands-On Exercise 3 Add code and test Cancel button Add code and test Delete button Create, add code and test the List form Add code for the GridHeadings and GridCells procedures Test the FlexGrid control

18 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.17 Summary...  A database is a collection of data  A table consists of rows (records) and columns (field)  A field is the smallest unit of data  A record is composed of several fields and stores data about a single entity  A flat-file database consists of a single table

19 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.18 Summary  Use the Type statement to create your own data types  The Microsoft FlexGrid control is designed to display tables or grids of data  The Birthday database demonstrates a simple flat-file database application has shortcomings that can be overcome by adding more code such as searching and handling deleted records

20 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.19 Practice with Visual Basic 1. WindChill Table 2. Personal Address Book 3. Practice with Access 4. Birthday Deletion Improvement

21 Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.20 Case Studies  Database Mystery  Beginning Database Design  Flat-file Database  FlexGrid Case Study


Download ppt "Chapter 7 Database Basics Tables, Records, and Fields 7 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton."

Similar presentations


Ads by Google