basics of database programming with vb6 by: mr. carl michael l. morados

22
Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Upload: jada-mclain

Post on 26-Mar-2015

225 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Basics of Database Programming with VB6

By: Mr. Carl Michael L. Morados

Page 2: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

What is a database?

Database – a collection of related data or information, that is stored, modified and transmitted.

Student Database

Personal Info

Grades

Payments

Page 3: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Structure of a Database

Tables – collection of related information Records –single piece of information Fields – smallest unit of information that is

useful to users.

Page 4: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Structure of a Database

Student Information Sheet

Name:Address:Contact No.:

Table

Record

Fields

Page 5: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Visual Basic and Database

Front End – the user interface, which the program uses to interact with the user.

Back End – the database, where all data coming from the user are saved, to be retrieved later.

Page 6: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Visual Basic and Database

The user interacts withthe program by user interface or screens.

(Visual Basic)

ADO ObjectDatabase Driver

(Database Application)

Page 7: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

What are database drivers?

It allows different programming languages to communicate or get information from different data sources.

Page 8: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Using the ADODC Object

ADODC (ActiveX Data Object) – an object used to connect a Visual Basic program to a database.

ADODC Object on the toolbox

ADODC Object when placed on the form

Page 9: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Inserting the ADODC Object

1. Go to Project menu, then choose Components. (or right click on the toolbox)

2. When the components dialog appears, choose Microsoft ADO Data Control 6.0.

Page 10: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Inserting the ADODC Object

Components Dialog Window

Page 11: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Connecting the ADODC to a database

Straight Connection Setting of the Database Provider and directly

specifying the path of the database (location). Using ODBC (Open Database

Connectivity) Creating a Data Source Name (DSN) using the

ODBC Administrator of Windows

Page 12: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Steps in Connecting ADODC

Right Click on the ADO Object Connect the ADO by using the Connection

String or ODBC Data Sources

Page 13: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Steps in Connecting ADODC

Choose the correct databaseprovider.

Page 14: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Steps in Connecting ADODC

Specify the correct path ofthe database

Test the connection if the ADODCwhere able to communicate withthe data source.

Page 15: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Steps in Connecting ADODC

Specify how the ADODC willconnect to the table.

Page 16: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Structure of an ADODC commands

<adodc name>.RECORDSET.<method><adodc name>.RECORDSET.<method>

The Name of the adodc object Refers to the tableobject

Methods that canbe done to a table

Page 17: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Types of ADODC methods

Record Operations Addnew – used to add records to the table. Delete – used to delete records from the table. Update – used to save records to the table. CancelUpdate – cancels any record-related

operations.

Page 18: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Types of ADODC commands

Record Navigation Find <parameters> - used to find or search

records, based on key fields. Movefirst – go to the first record. Movelast – go to the last record. Movenext – go to the next record. Moveprevious – go to the previous record. Move(record no.) – go to a specified record no.

Page 19: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Types of ADODC commands

Record Counters RecordCount – returns the number of records on

the table EOF – End of File, returns True if the record

pointer reaches the end of the table. BOF – Beginning of File, returns True if the record

pointer reaches the beginning of the table

Page 20: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Finding Records

FIND “[key field] like ‘comparing value’e.g.

adoSTUD.RECORDSET.FIND “[LName] like ‘Locsin’”

In finding records, always REFRESH the table first. to complete the code:

adoSTUD.REFRESH

adoSTUD.RECORDSET.FIND “[LName] like ‘Locsin’”

Page 21: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Using the SQL Statements

SQL (Structured Query Language) – is composed of series of statements and clauses, which, when combined, perform different actions.

Select Queries – returns a specific set of records, based on criteria

Action Queries – performs actions such as deleting, adding or updating records.

Page 22: Basics of Database Programming with VB6 By: Mr. Carl Michael L. Morados

Presentor: Mr. Carl Michael L. Morados

Basic Structure of Select

SELECT <fields> FROM <tablename> [<where> <condition> <order by>]

e.g.

Select * from StudInfo