You are on page 1of 20

CHAPTER 5

[Document subtitle]

INTAN SHAFINAZ BINTI ABD RAZAK


PTSB, KULIM
DATA ACCESS CONTROL
5.1. Know a database concepts.
5.1.1. Identify the database structure and terminology.
In simplest terms, a database is a collection of information. This collection is stored in well-defined
tables, or matrices.

The rows in a database table are used to describe similar items. The rows are referred to as
database records. In general, no two rows in a database table will be alike.

The columns in a database table provide characteristics of the records. These characteristics are
called database fields. Each field contains one specific piece of information. In defining a database
field, you specify the data type, assign a length, and describe other attributes.

Here is a simple database example:

In this database table, each record represents a single individual. The fields (descriptors of the
individuals) include an identification number (ID No), Name, Date of Birth, Height, and Weight.

Most databases use indexes to allow faster access to the information in the database. Indexes are
sorted lists that point to a particular row in a table. In the example just seen, the ID No field could be
used as an index.

A database using a single table is called a flat database. Most databases are made up of many
tables. When using multiple tables within a database, these tables must have some common fields to
allow cross-referencing of the tables. The referral of one table to another via a common field is called
a relation. Such groupings of tables are called relational databases.

In our first example, we will use a sample database that comes with Visual Basic. This database
(BIBLIO.MDB) is found in the main Visual Basic directory (try c:\Program Files\Microsoft Visual
Studio\VB98). It is a database of books about computers. Lets look at its relational structure. The
BIBLIO.MDB database is made up of four tables:

Authors Table (6246 Records, 3 Fields)


The Authors table consists of author identification numbers, the authors name, and the year born.
The Publishers table has information regarding book publishers. Some of the fields include an
identification number, the publisher name, and pertinent phone numbers. The Title Author table
correlates a books ISBN (a universal number assigned to books) with an authors identification
number. And, the Titles table has several fields describing each individual book, including title, ISBN,
and publisher identification

Note each table has two types of information: source data and relational data. Source data is actual
information, such as titles and author names. Relational data are references to data in other tables,
such as Au_ID and PubID. In the Authors, Publishers and Title Author tables, the first column is used
as the table index. In the Titles table, the ISBN value is the index.

Using the relational data in the four tables, we should be able to obtain a complete description of any
book title in the database. Lets look at one example:

Here, the book in the Titles table, entitled Step-by-step dBase IV, has an ISBN of 0-0280095-2-5
and a PubID of 52. Taking the PubID into the Publishers table, determines the book is published by
McGraw-Hill and also allows us to access all other information concerning the publisher. Using the
ISBN in the Title Author table provides us with the author identification (Au_ID) of 171, which, when
used in the Authors table, tells us the books author is Toby Wraye.

We can form alternate tables from a databases inherent tables. Such virtual tables, or
logical views, are made using queries of the database. A query is simply a request for
information from the database tables. As an example with the BIBLIO.MDB database, using
pre-defined query languages, we could ask the database to form a table of all authors and
books published after 1992, or provide all author names starting with B. Well look briefly at
queries.

Keeping track of all the information in a database is handled by a database management


system (DBMS). They are used to create and maintain databases. Examples of commercial
DBMS programs are Microsoft Access, Microsoft FoxPro, Borland Paradox, Borland dBase,
and Claris FileMaker. We can also use Visual Basic to develop a DBMS. Visual Basic shares
the same engine used by Microsoft Access, known as the Jet engine. In this class, we will
see how to use Visual Basic to access data, display data, and perform some elementary
management operations.

5.2. Understand the ActiveX Data Object.


5.2.1. Describe ActiveX Data Object (ADO).

ADO (ActiveX Data Objects) is another data access method. ADO data model has a collection of
objects using which you can access and manipulate any database that is based on OLEDB ( Object
Linking and Embedding, Database) interface (more about it later). ADO model is simple. It has
fewest objects in its object model. ADO is the data model for databases that are accessed using
OLEDB interface, where as RDO is the data model for databases that are accessed using ODBC
interface.

What is OLEDB (OLE Database)?


OLEDB is an entirely new method to connect to databases. OLEDB is replacing ODBC. OLEDB
provides flexibility and ease of use than ODBC. OLEDB was designed to allow access to data of
various formats. That means the data need not be in the form of a relation database and accessed
using SQL.

OLEDB needs a provider, which is a program that can sit between the application and the database
(something like an ODBC (Open Database Connectivity) driver). So when you want to access a
database using OLEDB interface, you have to make sure that you have OLEDB provider for that
database. Microsoft has provided the following OLEDB providers.

Microsoft OLE DB provider for ODBC drivers


Microsoft Jet 3.51 OLEDB provider
Microsoft OLE DB provider for Oracle
Microsoft OLE DB provider for SQL Server
Microsoft OLE DB provider for Directory Services

Note: You can access any ODBC data source through OLEDB using OLE DB provider for ODBC
drivers, if no OLEDB provider is available.

5.2.2. Distinguish between data control and data-bound controls.


5.3. Apply database application using ActiveX Data Object.
5.3.1. Use ActiveX Data Object (ADO) in program.
The Data-Bound Controls: You can bind certain controls to the data control, the remote data
control, and the ADO data control, and those controls are called bound controls. To bind a
control to a database control, you use properties like DataSource to specify the database
control, and then use properties like DataField or BoundColumn to specify what field to
display in the bound control, as well see. Here are the controls that can function as bound
controls:
Picture boxes
Labels
Text boxes
Checkboxes
Image controls
OLE controls
List boxes
Masked edit controls
Rich text boxes
Combo boxes
In addition, there are special controls that are designed to be used as bound controls:
DBList
DBCombo
FlexGrid
MSFlexGrid
Finally, a number of bound controls are specially built to be used with the ADO control only:
DataList
DataCombo
DataGrid

Using Data Control:

1. Create a database using MSAccess, Oracle or Sql server named st_detail and a
table student having fields (name, roll no, class).

2. Start a new Standard EXE project and design a Form that looks like

3. Start by drawing a Data control at the bottom of the Form. The Data control is your
gateway to the database.

4. With the Data control selected, locate its DatabaseName property, and set the path
to st_detail database.

5. Locate the RecordSource property in the Properties window, and drop down the
list of available entries. Youll see a list of all the tables in the st_detail database. Select
the student table.

6. Place three textboxes on the Form.


7. Select the first textbox, and in the Properties window locate its DataSource
property. Set it to Data1.

8. Set the DataField property of the textbox to Name. The DataField property is a
drop-down list with the names of all fields in the student table.

9. Set the DataSource property of the other textboxes to Data1, and set the DataField
property to Roll No, and Class.

Now run the application. The textboxes will display the values of the corresponding fields of
the student table. Using the Data controls buttons, you can move through the records (rows)
of the table. Clicking the leftmost button displays the first record of the table, and clicking the
button next to it displays the previous record. Clicking the rightmost button displays the last
record of the table, and clicking the button next to it displays the next record.

Next section will be show step by step in developing a standalone database program.

5.4. Design database application.


5.4.1. Create a project to display data from database tables in bound controls.
5.4.2. Create a lookup table for a database field.
5.4.3. Design an application using database

In this section, we use LAB6 SAMPLE as a learning tools to make understanding easy.

CREATE THE DATABASE


APPLY COMPONENT

BUILD FORM
ADODC SETTINGS
DATA GRID SETTING

RUN THE APPLICATION


THE SOURCE CODE
Option Explicit

Dim found As Integer

COMMAND BUTTON- CLEAR

Private Sub strClear_Click()

strfname = ""

strlname = ""

strcourse = ""

strmatrik = ""

straddress = ""

strfname.SetFocus

End Sub
COMMAND BUTTON- ADD

Private Sub strcmdadd_Click()

jmvtc.Refresh

'Inform the database table that you're going to add new record

jmvtc.Recordset.AddNew

'let the fields of the database table hold the value on lyour textboxes

jmvtc.Recordset.Fields("fname") = strfname

jmvtc.Recordset.Fields("lname") = strlname

jmvtc.Recordset.Fields("course") = strcourse

jmvtc.Recordset.Fields("matrik") = strmatrik

jmvtc.Recordset.Fields("address") = straddress

'Save the record on the database table

jmvtc.Recordset.Update

'Inform the user

MsgBox "Add New Successful!", vbInformation, "SUCCESSFUL"

Call strClear_Click

End Sub

COMMAND BUTTON- DELETE

Private Sub strcmddelete_Click()

jmvtc.Recordset.Delete

MsgBox "Record Deleted!", vbInformation, "TRASH"

Call strClear_Click

End Sub
COMMAND BUTTON- EDIT

Private Sub strcmdedit_Click()

'Since ADO doesn't have a direct edit option, we must search the record first before attempting to change the
record

jmvtc.Recordset.Delete

jmvtc.Refresh

jmvtc.Recordset.AddNew

jmvtc.Recordset.Fields("fname") = strfname

jmvtc.Recordset.Fields("lname") = strlname

jmvtc.Recordset.Fields("course") = strcourse

jmvtc.Recordset.Fields("matrik") = strmatrik

jmvtc.Recordset.Fields("address") = straddress

jmvtc.Recordset.Update

MsgBox "Edit record successful!", vbInformation, "SUCCESSFUL"

Call strClear_Click

End Sub

COMMAND BUTTON- SEARCH

Private Sub strsearch_Click()

'always Call & refresh your database if you're going to search any record(table),except for editing your record

jmvtc.Refresh

'This section is used for searching

Do While Not jmvtc.Recordset.EOF = True

If jmvtc.Recordset("fname") = strfname And jmvtc.Recordset("lname") = strlname Then

found = True

Exit Do

Else

jmvtc.Recordset.MoveNext

found = False

End If

Loop
'This section is used for searching

If found = True Then

'used for displying the found record

MsgBox "Record Found!", vbInformation, "MATCH FOUND"

strfname = jmvtc.Recordset("fname")

strlname = jmvtc.Recordset("lname")

strmatrik = jmvtc.Recordset("matrik")

strcourse = jmvtc.Recordset("course")

straddress = jmvtc.Recordset("address")

Else

'used for displaying the found/not found record

MsgBox "Record Not Found!", vbExclamation, "NO MATCH FOUND"

strfname.SelStart = 0

strfname.SelLength = Len(strfname.Text)

strfname.SetFocus

End If

End Sub

Remarks:

Please refer to ADO.PDF


The sample of ADO program, please refer to Example Lab 6 folder.

REFERENCES:

http://free-visualbasic-tutor.blogspot.my/2011/07/activex-data-objects-ado.html

http://www.freetutes.com/learn-vb6/lesson22.1.html

http://studywithgoogle.blogspot.my/p/visual-basic-theory-index.html
DEC 5062 (VB)- LAB # :
BIL NAMA NO PENDAFTARAN
1.
2.

Rubric for Laboratory


NEEDS NOT
EXCELLENT SATISFACTORY
CRITERIA IMPROVEMENT COMPLETED Weightage Marks
+3 +2
+1 +0
Interface design is Interface design Interface design is Interface design
professional and meets basic client cluttered, messy, or has not been
Interface
Design

provides user specifications confusing completed


2 /6
instructions and/or
where necessary GUI suffers from Interface design Lets others do
only one of the does not meet client the work.
All properties of Most properties of Minimal properties Control
Properties

controls are set to controls are set to of controls have properties have
Program

meet meet specifications been set and/or not been set


2 /6
specifications of of the problem. controls have not
the problem. been named Lets others do
the work.
Concepts from class Program code
Error Program Code

Concepts from Concepts from class are not applied to has not been
class are applied, are applied, the program completed
4 /12
Code is straight however, code
forward, contains unused VB Lets others do
consistent, logic elements the work.
all requirements contains 1 run time contains more than Cant be run at
met and runs with bug or error 1 run time bug or all
no errors error
Lets others do
Program runs Program code the work. 3.5 /10.5
without errors contains major
The program was The program was The program was The program 2 /6
Delivery

delivered on time delivered within 24 delivered within 72 was more than 3


hours of the due hours of the due days overdue
date date

The student gave The student The student The student did 1 /3
Effort

an effort far completed the finished the project, not finish the
beyond the project in an above but it lacks finishing work in a
requirements of average manner, yet touches or can be satisfactory
the project more could have improved upon manner.
been done with little effort.
Can be left to do Needs minimal Required no more Unable to work 2.5 /7.5
Collaboration and Initiative
Self Reliance

alone most of the supervision supervision without


time following following following continuous help
instruction. instruction instruction than from lecturer.
might be expected

The whole group The whole group The group did not There was little 2 /6
worked incredibly worked well work very well or no group
Group

well together together together collaboration,


everyone
worked on their
own.
*** Project NIL NIL NIL
Embellishme*

embellishment
shows extra work,
challenges the
nt

students 1 /3
programming
TOTAL
/60

REMARKS:
TUANKU SULTANAH BAHIYAH POYTECHNIC

ELECTRICAL ENGINEERING DEPARTMENT

VISUAL BASIC PROGRAMMING

DEC 5062

PROJECT (20%)

Title: DATA ACCESS USING ADO DATA CONTROL

Instruction:
i. Form your group 2 to 3 person.
ii. Build an application that have an integration of database (The same application in
Laboratory 6)
iii. Include the application with complete documentation including:
a. Project proposal and project plan (Gantt chart).
b. Requirement specification
c. Test description and results
d. Source code
e. User Interface or application
f. References
iv. The rubric for documentation AND presentation are shown below:
Items: 0 1 2 3 4 5 Remarks

PROJECT

Can solve the given tasks within a stipulated time


CLO4
frame. (time management)

Project proposal and project plan (Gantt chart). CLO4

Complete the documentation with Introduction,


Scope and Example of similar system that had
implement the database.
Requirement specification & User Interface or CLO4
application
The chosen application is realistic and make sense.
User friendly application.
Test description and results CLO4

The troubleshooting process is included and


discussed.
Source code CLO4

The originality of the source code & have some


modification to show the originality of idea.
References CLO4

Include relevant references to build the application.


Oral presentation: Speaking CLO4

Organize ideas and communicate appropriately to - - -


listeners
Oral presentation: Tools CLO4
- - -
Able to use technology in Presentation.
TOTAL:

0 represents completely false

1 represents just barely true

2 represents somewhat true but mostly untrue

3 represents about half right

4 represents mostly true

5 represents completely true

Lecturers Reference:

Generic skills marks:

You might also like