Step 2: Connect to a database

<< Click to Display Table of Contents >>

Navigation:  Application development > Introduction to BDE programming > BDE Programming in Borland C/C++ > Basic procedure >

Step 2: Connect to a database

Previous pageReturn to chapter overviewNext page

Now you are ready to connect to a database.

All table access must be performed within the context of a database. Local databases generally use what is referred to as the "STANDARD" database, which is used in this example.

The preferred method is to create an alias to a local directory and use that as the database. This permits easy future modification if one day it is decided to move the application from using dBASE tables to using InterBase tables.

You use the function DbiOpenDatabase to open a database:

 

hDBIDb                                hDb = 0;// Handle to the Database

 

Chk(DbiOpenDatabase(

   NULL,                                                      // Database name - NULL for standard Database

   NULL,                                        // Database type - NULL for standard Database

   dbiREADWRITE,                                // Open mode - Read/Write or Read only

   dbiOPENSHARED,                                // Share mode - Shared or Exclusive

   NULL,                                        // Password - not needed for the STANDARD database

   NULL,                                        // Number of optional parameters

   NULL,                                        // Field Desc for optional parameters

   NULL,                                        // Values for the optional parameters

   &hDb));                                        // Handle to the database