12. Database
Projects
Databases and
Database Management Systems:
2.
Binding
Data
Control
with
Text
Boxes:
In
the
last
example
the
Data
Control
was
bound
to
the
DBGrid
control
so
that
the
output
was
displayed
in
the
DBGrid
box. This
time
we
will
bind
the
Data
control
with
text
boxes
binding
each
field
of
the
database
with
a
text
box. In
addition
we
will
add
facilities
for
add,
delete,
edit,
find
and
seek
methods
to
operate
on
the
database. Drag
a
Data
Control, four
label
boxes,
four
text
boxes
and
thirteen
command
buttons,
size
them,
caption
them
and
position
them
as
shown
in
the
figure
3.

Figure
3
Set
the
Database
Name
property
by
actual
browsing
and
the
record
source
property
for
the
Data
control
object. For
each
of
the
text
box
set
the
data
source
property
as
D1
and
data
field
property
as
the
name
of
the
field
which
it
is
to
display.
It
may
be
noted
that
the
seek
method
will
work
only
with
Table
type recordset
and
so
set
the
Recordset
type
property
of
the
data
control as
‘0-Table’. For
working
with
the
Find
method,
set
the
Recordset
type
property
as
1-Dynaset. Open
the
code
window
for
the
different
command
buttons
and
enter
the
codes
as
shown
in
the
figure
3a.
Run
the
project
and
check
the
function
of
each
command
button. A
typical
output
is
shown
in
the
figure
4.
Private
Sub
add_Click()
Data1.Recordset.AddNew
Text1.SetFocus
End
Sub
Private
Sub
delete_Click()
Data1.Recordset.delete
End
Sub
Private
Sub
edit_Click()
Data1.Recordset.edit
End
Sub
Private
Sub
exit_Click()
Unload
Me
End
Sub
Private
Sub
fieldcount_Click()
MsgBox
"Number
of
fields
"
&
Data1.Recordset.Fields.Count
End
Sub
Private
Sub
find_Click()
Dim
c As
String
c
=
InputBox("enter
the
empno
whose
record
is
required")
Data1.Recordset.FindFirst
"empno
="
&
"'"
&
c
&
"'"
End
Sub
Private
Sub
movefirst_Click()
Data1.Recordset.movefirst
End
Sub
Private
Sub
movelast_Click()
Data1.Recordset.movelast
End
Sub
Private
Sub
movenext_Click()
Data1.Recordset.movenext
If
Data1.Recordset.EOF
Then
MsgBox
"you
are
on
the
last
record"
Data1.Recordset.movelast
End
If
End
Sub
Private
Sub
moveprevious_Click()
Data1.Recordset.moveprevious
If
Data1.Recordset.BOF
Then
MsgBox
"you
are
on
the
first
record"
Data1.Recordset.movefirst
End
If
End
Sub
Private
Sub
reccount_Click()
Data1.Recordset.movelast
MsgBox
"Number
of
Records
"
&
Data1.Recordset.RecordCount
End
Sub
Private
Sub
save_Click()
Data1.Recordset.Update
End
Sub
Private
Sub
seek_Click()
Dim
c
c
=
InputBox("enter
the
empno
whose
record
is
required")
Data1.Recordset.Index
=
"empno"
Data1.Recordset.seek
"=",
c
End
Sub
Figure
3a

Figure
4
   |