In this section we show how to execute SQL queries and fetch data using ODBC, DAO, and ADO. First, you need a database. The examples for this chapter include an Access database called pydbdemos.mdb . You could as easily use any database you can access, of course modifying the SQL statements as needed. The sample database consists of a list of clients and invoices, with the structure shown in Figure 13.2.
If you wish to use the sample database, you need to configure an ODBC data source as follows:
Click on Start → Settings → Control Panel → 32-bit ODBC → User (or system) DSN → Add.
Select Microsoft Access Driver from the list of drivers.
Enter the name PYDBDEMOS in the box for Data Source Name.
Click the Select button and locate the file pydbdemos.mdb.
Click OK. The new data source should now be visible in the list.
Click OK to close the ODBC Data Source Administrator. Some versions of Windows contain a bug that causes an error message at this point. Ignore any messages; your data source is registered correctly.
Since Access isn’t a server, we have worked with Sybase SQL Anywhere for some of the advanced examples. This is an excellent commercial database engine costing little more than Access and part of a range of products ranging from embedded database engines to enterprise servers. We’ve kept the Sybase examples to a minimum ...