To install the DAO SDK, run the Setup program. For more information about installing the DAO SDK, see “DAO SDK Files” later in this chapter. Using Visual C++, open the Employee.dsw project workspace file, which is located in the \Samples\Employee folder. This file contains all the settings needed for the Employee application. To create the application, Employee.exe, click the Build command on the Build menu.
See Also For more information, see “Installing DAO on Another Machine” in the DAO SDK Help.
Note To run this application, the DAO run-time libraries must be properly installed. By default, the DAO SDK Setup program installs those libraries. Setup can also be modified to install them without including the other SDK contents (such as header files and import libraries, which only the application developer would require).
The DAO SDK Setup program adds header, library, and source file directories to your Visual C++ environment. The Employee.dsw project workspace file contains the specific settings for building the Employee application.
In addition to the corresponding header files for each source file, the Setup program installs the following files:
Because the dbDAO classes use MFC classes (such as CObject and COleVariant), your application must include the appropriate files for them. Likewise, because the dbDAO classes are built on top of the DAO Automation interfaces, the various OLE header files must be included. Stdafx.h includes all the necessary header files for building your dbDAO application.
The Employee application uses the MFC document/view architecture. The document portion manipulates the data, so most of the dbDAO code resides there. The view portion contains display code. The Employee application is form-based and derives from the MFC CFormView class. The focus of this discussion is the dbDAO code, so details about using MFC are not provided.
See Also For more information about the MFC document/view architecture, see the MFC documentation that comes with Visual C++.
The document (Daoemdoc.cpp) holds the database connection and defines the following member variables:
public: CdbRecordset m_cEmpRecordSet; BOOL m_bConnected; BOOL m_bEmptyTable; protected: CdbDBEngine m_cDBEngine; CdbDatabase m_cEmpDatabase; CdbBookmark m_cLastGoodRecord;
These declarations are similar to Visual Basic declarations using the Dim statement. Note that dbDAO classes in the preceding declarations are prefaced by the Cdb prefix.
The document contains member variables for the engine, the database connection, and the recordset that is displayed by the form — that is, m_cDBEngine, m_cEmpDatabase, and m_cEmpRecordSet, respectively. The m_bConnected member variable is a Boolean value that is TRUE if the connection to Employee.mdb is open; otherwise, it is FALSE. The m_bEmptyTable member variable is a Boolean value that is TRUE if the Employees table does not contain any records; otherwise, it is FALSE.
A bookmark, the m_cLastGoodRecord member variable, is defined for use by the various positioning functions to keep track of the last record visited. Note that dbDAO defines the CdbBookmark class for bookmarks, whereas bookmarks are typed as Variant in Visual Basic.
Because various code modules use the recordset, connected, and empty table flags, they are given public access. The engine, database, and bookmark member variables are given protected access, so that other code modules cannot modify their values.
The member variables are initialized upon creation of the document. The OnNewDocument member function is overridden in order to perform the initialization. This function also initializes the DBEngine object. For more information about other ways of initializing the engine, see “Initializing CdbDBEngine” later in this chapter. The OnNewDocument function calls the ConnectToDatabase function, which is described in the following section.