Presentation on Rad-To-Database hookup
Download
Report
Transcript Presentation on Rad-To-Database hookup
RAD to Database Connection
Glenn Campbell
[email protected]
Learning Outcomes
After this lesson you will be familiar with:
TclODBC
Linking RAD application to database
Creating an ODBC Data Source Name (DSN)
TCL commands
Using SQL to query a database
TclODBC
Extension to TCL (Tool Command Language)
which allows access to databases
Uses standard ODBC interface
The Rapid Application Developer (RAD) can
be configured to link to a database
We will use MS Access for creating the
database
Initial Steps
Before you begin, do the following:
1.
2.
Download and install TclODBC from course
website
Create a database in MS Access called
name.mdb e.g. student.mdb
We can now create a link between the
database and the RAD application
Testing TclODBC
Refer to Exercise 20 of Tutorial 12 for
information on how to test TclODBC in the
CSLUsh window.
When you are satisfied that TclODBC is
working, you can then create a link between
your RAD application and the Database.
RAD to database connection
The RAD to database connection is achieved using
the following steps:
Step 1: Create a link between the RAD and the
database
Step 2: Create an ODBC Data Source Name
(DSN) for your database
Step 3: Create a database object to open a
connection to the database
Step 4: Use SQL to query the database
Step 1: RAD – database link
Download TclODBC package into the
. . . \CSLU\Toolkit\2.0\pkg\tclodbc2.2 directory
Use the following command to create a link between
RAD and the database:
package require tclodbc
This command loads the TclODBC program which
creates a link between RAD and the database
This (and any other) TCL command can be inserted
into the ‘On Exit’ tab of an Action Object
Step 2: Create an ODBC DSN
Select:
Start | Control Panel | Administrative Tools |
Data Sources (ODBC) | Add
Now enter required information. For example,
in this example, enter ‘student’ as the Data
Source Name (i.e. the name of the database)
Remember to select ‘Microsoft Access Driver’
and browse for the database you wish to link
to.
Step 3: Create database object
Use the command database to create a
database object, db which refers to the DSN
created in Step 2
To do this use the following command:
Database db name
where name is the name of the database, e.g.
‘student’
Step 4: Query the database
The database can now be queried using SQL
Again, the code is entered into the Action object:
For example:
set getDetails [db "Select Name from StudentRecords
where StudentNumber = $value"]
where Name and StudentNumber are all fields in the
StudentRecords table of the student database
Further Information
Paul Mc Kevitt’s course website
http://www.infm.ulst.ac.uk/~paul/com556m2/
CSLU Toolkit webpage
http://cslu.cse.ogi.edu/toolkit/
Email me:
[email protected]