ISM 3230 Introduction to Programming

 Chapter 11: Database Files
Chapter 11 Student Learning OBJECTIVES:

Upon completion of this chapter, you will be able to:

      1. Use database terminology correctly.
      2. Differentiate between the data control and data-bound controls.
      3. Create a project to view an existing database table.
      4. Set up a lookup table for a database field.
      5. Change records, add new records, and delete records in a database table.
      6. Write code to help prevent user errors

Visual Basic and Database files

Database Terminology

Below is a portion of a Microsoft Access table with table elements labeled.
Table is but one of several tables that comprise the database.
Database tables, queries, forms, and other elements are stored in a single Access File (for example, the file named RnRBooks.mdb)

Creating DBs for use by VB

Using the data control

Data control:

Data-Bound Control Properties

Viewing a Database File

Navigating the database in code

The following code helps to establish a default location for the database--the same location as the application:

Private Sub Form_Load()

End Sub

 

RecordSet Methods

BOF and EOF are properties of the Recordset object.

Using List & Combo Boxes as Data-Bound Controls

Lookup Table & Navigation

Updating a Database File

Adding and Updating Records

Deleting Records

With datBooks.Recordset

.Delete

.Movenext

End with

Example Delete

Private Sub cmdDelete_Click()

'Delete the current record

With datBooks.Recordset

.Delete

.MoveNext

If .EOF Then 'Reached end of file

.MovePrevious 'Go to previous record

If .BOF Then 'No records left if true

MsgBox "Database empty",,"No Records"

End If

End If

End With

End Sub

Preventing Errors

Cancel

Hands on Programming Example


Chapter Summary:

OBJECTS

 

PROPERTIES

 

METHODS

Data control

 

BOF

 

AddNew

RecordSet

 

Connect

 

Delete

   

DatabaseName

 

MoveNext

   

DataField

 

MoveLast

   

DataSource

 

MovePrevious

   

EOF

 

MoveFirst

   

RecordSource

 

Update