You are on page 1of 19

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 : Data Control’s methods
Teaching Aids : PPTs
CCP603.17 1
Objective :

On completion of this period, you would be


able to:
 Know Data Control’s methods

CCP603.17 2
Structure Of The Period :

 Connecting Data Control to Table


 Data Control’s navigation methods
 Data Control’s record manipulation methods

CCP603.17 3
Recap :
 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.17 4
Connecting a Table Using Data
Control :
 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.17 5
Connecting a Table Using Data
Control : (Contd..)
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.17 6
Connecting a Table Using Data
Control : (Contd..)

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.17 7
Data Control’s Navigation Methods :

There are 4 important methods of Data Control


that help in navigating through records
They are:
 MoveFirst
 MoveLast
 MoveNext
 MovePrevious

CCP603.17 8
Data Control’s Methods :
 To implement these methods, command buttons
are used
 Add four command buttons to the button of the
form
 Set their ‘caption’ properties to MoveFirst,
MoveLast, MoveNext and MovePrevious
respectively
 Set the ‘visible’ property of data control to ‘false’
 Then the form looks as follows:
CCP603.17 9
Form Design View

CCP603.17 10
 Now double click on the MoveFirst command
button and enter the following code in the code
window
 Data1.Recordset.MoveFirst

 Similarly, double click the other 3 command


buttons also and enter the respective code lines
in the code window:
 Data1.Recordset.MoveLast
 Data1.Recordset.MoveNext
 Data1.Recordset.MovePrevious

CCP603.17 11
Record Manipulation methods
• The record manipulation operations and the methods to
carry them out are
Addnew– for adding records
Update – for saving
Delete - for deleting records.
CancelUpdate – for cancelling records
• These methods are used with Data controls as follows:
Data1.Recordset.Addnew etc.
• The above code can be attached to buttons and used
as needed just like with navigation methods
CCP603.17 12
Code Window

CCP603.17 13
 Run the program and scroll through the
records with the navigation buttons on the
data control

CCP603.17 14
Summary :
 Data Control has four important methods
for record navigation
 Using these methods, records can be
browsed one by one

CCP603.17 15
Quiz :

1. What are the methods of data control ?


Ans: MoveFirst
MoveLast
MoveNext
MovePrevious

CCP603.17 16
Frequently Asked Questions :

1. List out the important methods of Data


Control.

2. Briefly explain the procedure of


implementing the methods of Data Control.

3. Briefly explain the record navigation


methods.

CCP603.17 17
Assignment :

1. Create a new form in Visual Basic.


2. Connect a table using data control.
3. Display the data obtained through text
boxes.
4. Add 4 command buttons to the form.
5. Write code for the buttons.
6. Show the record navigation using the
command buttons.

CCP603.17 18
Thank You

CCP603.17 19

You might also like