12. Database
Projects
In this lesson we will consider some projects using
DAOs, ODBC and
ADOs..
Data
Access
through
ODBC:
A
Data
Access
Object
can
be
connected by
a ODBC
driver
and
data
objects
can
be
accessed
and
printed
in
the
Debug
window.
First
you
set
up a
form
with
a
single
command
button
as
shown
in
the
figure
10..
Figure10
In
the
code
window
of
the
command
button
enter
the
code
as
shown
in
the
figure
10a. Save
and
run
the
project. You
will
get
the
output
for
all
the
SQL
queries
entered
in
the
program. You
can
modify
the
program
so
as
to
enter
the
queries
from
an
input
text
box
at
the
time
of
execution. A
typical
output
is
shown
in
the
figure
11.
Private
Sub
Command1_Click()
Dim
wRKodbc
As
Workspace
Dim
conpubs
As
Connection
Dim
D As
Database
Dim
r As
Recordset
Set
wRKodbc
=
CreateWorkspace("NewODBCWorkspace1",
_
"admin",
"",
dbUseODBC)
'Set
conpubs
=
wRKodbc.OpenConnection("Connection1",
dbDriverPrompt)
Set
conpubs
=
wRKodbc.OpenConnection("Connection2",
, ,
_
"ODBC;DATABASE=PAYROLL;UID=ADMIN;PWD=SYSTEM;DSN=D1")
Debug.Print
""
Set
r =
conpubs.OpenRecordset("SELECT
*
FROM
EMPLOYEE")
Do
While
Not
r.EOF
Debug.Print
r(0),
r(1),
r(2),
r(3)
r.MoveNext
Loop
End
Sub
Figure
10a

Figure11
   |