You are on page 1of 18

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH
Name : Y. Vijaya Bhaskara Reddy
Designation : Senior Lecturer
Branch : Commercial and Computer
Practice
Institute : G.P.W ., Kakinada
Year/Semester : VI Semester
Subject : Visual Basic – II
Subject Code : CCP – 603
Topic : Database Programming
Duration : 50 Mts
Sub Topic : Connecting to database tables
Teaching Aids : PPTs
CCP603.16 1
Objective :

On completion of this period, you would be


able to:
 Explain the process of connecting database
tables of a database using data control

CCP603.16 2
Structure Of The Period :

 Location of Data Control Icon


 Adding the Data Control on the form
 Procedure of connecting Database tables

CCP603.16 3
Recap :

 Data control is used to provide access to


data in databases through bound controls
on the form
 It is also used to move from one record to
another in a database
 It can be placed on the form by double
clicking the control available in the Tool
Box

CCP603.16 4
Location of Data Control Icon :

It is located at the bottom


of the Tool Box

Data Control

CCP603.16 5
Adding the Data Control to the
Form :
 Double Click on the Data Control Icon in
the Tool Box
 A new Data Control with name “Data1” is
placed on the Form, which looks as shown
below:

CCP603.16 6
Procedure of connecting
database tables :
Properties window of Data Control

CCP603.16 7
Procedure of Connecting
Database Tables :
 Press Ctrl+N in Visual Basic to start a new
project
 From the New Project dialog box, select
Standard EXE and Click OK
 Add two text boxes to the top of a form
 Double-click the data control in the Tool Box
to add it to the form
 Drag the newly added data control to position
it below the Text boxes
CCP603.16 8
Procedure of Connecting
Database Tables :
This example uses ‘Authors’ tabel of Biblio.mdb
supplied by Microsoft
 Widen the data control to see its caption. It
looks as shown below
 Remove the text of Text boxes

CCP603.16 9
Procedure of Connecting
Database Tables :
Set the properties of the data control as follows:

 Caption : Authors table


 Connect : Access
 Database Name : C:\Program Files\Microsoft
Visual
Studio\VB98\biblio.mdb
 Recordeset Type : 1-Dynaset
 Record Source : Authors
CCP603.16 10
Procedure of Connecting
Database Tables :

Set the properties for the first text box as follows:


 Data Source : Data1
 Data Field : Author
Set the properties for the second text box as follows:
 Data Source : Data1
 Data Field : Au_ID

CCP603.16 11
Procedure of Connecting
Database Tables :
 Run the program and scroll through the records
with the navigation buttons on the data control
 When clicked on Move First, it shows the first
record as shown below:

CCP603.16 12
Procedure of Connecting
Database Tables :
 When clicked on Move Last, it shows the last
record as shown below:

CCP603.16 13
Summary :
 Data Control is used to connect database
tables to the form in Visual Basic
 By setting the Database Name and Record
Source properties of data control, tables
are connected
 To display the data, text boxes are used
 Data Source and Data Field properties of
text box are used for this purpose

CCP603.16 14
Quiz :
1. How Data Control is added to the form ?
Ans: By double clicking the icon in tool box

2. What are the two important properties to be set


for a data control ?
Ans: Database Name and Record Source

3. What are the properties to be set for text boxes


to display the data from data control
Ans: Data Source and Data Field
CCP603.16 15
Frequently Asked Questions :

1. Explain the procedure of connecting


database tables to the form using a data
control.

2. List out the important properties of a Data


Control

3. List out the properties of Text Box to


display data from data control

CCP603.16 16
Assignment :

1. Create a new form in Visual Basic.


2. Add a data control to it.
3. Set its properties, as explained now to
connect a table.
4. Display the data obtained through text
boxes.

CCP603.16 17
Thank You

CCP603.16 18

You might also like