Professional Documents
Culture Documents
[Document subtitle]
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.
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:
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.
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.
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.
Note: You can access any ODBC data source through OLEDB using OLE DB provider for ODBC
drivers, if no OLEDB provider is available.
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.
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.
In this section, we use LAB6 SAMPLE as a learning tools to make understanding easy.
BUILD FORM
ADODC SETTINGS
DATA GRID SETTING
strfname = ""
strlname = ""
strcourse = ""
strmatrik = ""
straddress = ""
strfname.SetFocus
End Sub
COMMAND BUTTON- ADD
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
jmvtc.Recordset.Update
Call strClear_Click
End Sub
jmvtc.Recordset.Delete
Call strClear_Click
End Sub
COMMAND BUTTON- EDIT
'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
Call strClear_Click
End Sub
'always Call & refresh your database if you're going to search any record(table),except for editing your record
jmvtc.Refresh
found = True
Exit Do
Else
jmvtc.Recordset.MoveNext
found = False
End If
Loop
'This section is used for searching
strfname = jmvtc.Recordset("fname")
strlname = jmvtc.Recordset("lname")
strmatrik = jmvtc.Recordset("matrik")
strcourse = jmvtc.Recordset("course")
straddress = jmvtc.Recordset("address")
Else
strfname.SelStart = 0
strfname.SelLength = Len(strfname.Text)
strfname.SetFocus
End If
End Sub
Remarks:
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.
controls are set to controls are set to of controls have properties have
Program
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
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
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
embellishment
shows extra work,
challenges the
nt
students 1 /3
programming
TOTAL
/60
REMARKS:
TUANKU SULTANAH BAHIYAH POYTECHNIC
DEC 5062
PROJECT (20%)
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
Lecturers Reference: