12. Database
Projects
In this lesson we will consider some projects using
DAOs, ODBC and
ADOs..
2.
Project
using
DAO
object
TableDef:
In
this
project
data
are
added
to
the
table
using
text
boxes
and
the
Addnew
method. The
input
form
appears
as
shown
in
the
figure
4.

Figure
4
Enter
the
code
in
the
code
window
as
shown
in
the
figure
4a.
Save
and
run
the
project.
The
output
window
will
look
as
in
the
figure
5. Clicking
the
display
button
will
update
the
debug
window
and
clicking
the
refresh
button
will
update
the
DBGrid
window.
Dim
db
As
Database
Dim
rs
As
Recordset
Private
Sub
Command1_Click()
Set
db =
OpenDatabase("d:\rr2\college")
Set
rs =
db.OpenRecordset("author",
dbOpenTable)
rs.AddNew
rs("authorid")
=
Text1.Text
rs("authorname")
=
Text2.Text
rs.Update
rs.Close
End
Sub
Private
Sub
Command2_Click()
Set
db =
OpenDatabase("d:\rr2\college")
Set
rs =
db.OpenRecordset("author",
dbOpenTable)
Do
While
Not
rs.EOF
Debug.Print
rs(0),
rs(1)
rs.MoveNext
Loop
rs.Close
End
Sub
Private
Sub
Command3_Click()
Set
db =
OpenDatabase("d:\rr2\college")
Set
rs =
db.OpenRecordset("author",
dbOpenTable)
rs.MoveLast
rs.Delete
rs.Close
End
Sub
Private
Sub
Command4_Click()
Data1.Refresh
End
Sub
Figure
4a

Figure
5
   |