130 likes | 246 Views
RAD to Database Connection. Glenn Campbell Campbell-g8@ulster.ac.uk. 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.
E N D
RAD to Database Connection Glenn Campbell Campbell-g8@ulster.ac.uk
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: • 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, dbwhich 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
Access 2007 Considerations • Note that this presentation is related to MS Access 2003 • It does work with MS Access 2007 • But there may be some subtle changes in the way tclODBC is used
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: Campbell-g8@ulster.ac.uk