SUMMARY
The DAOTable sample (Daotbl.exe) demonstrates how to use
the MFC DAO classes to create the following common database objects: databases,
tables, queries, fields, and indexes. This dialog-based application maps the
properties of these objects to controls the user can set or view. The program
source code is organized so that most database interaction is isolated from the
user interface code to ease finding examples of how to use MFC DAO.
In addition to demonstrating the use of the MFC DAO classes, this sample can be
a useful tool for creating simple Microsoft Access databases. You can create
.mdb files from scratch, create and delete tables and queries, add and delete
fields and indexes in the tables, and modify existing queries.
The
following files contain the code that performs the database operations.
Additional files in the project provide the user interface and high level
database manipulation.
QUERYDEF.CPP, .H -- functions to create and use queries
TABLEDEF.CPP, .H -- functions to create and use tables
FIELD.CPP, .H -- functions to create and use fields
INDEX.CPP, .H -- functions to create and use indexes
DATABASE.CPP, .H -- functions to create and use databases
To use this code and the MFC DAO classes, you must have Visual
C++ 4.0 or later.
NOTE: Beginning with Visual C++ 4.1, the DAOTable
sample is included with the Visual C++ CD.
Special Note for Visual C++ 4.1 Users
The DAOTABLE sample that shipped with Visual C++ 4.1 contains a
bug that will prevent you from creating fields that are of any type other than
text. To correct this problem, you can download the fixed sample as directed
below or make the following correction to the ADDTBDLG.CPP file:
Replace this line
m_FI.m_bAllowZeroLength = TRUE;
with this line:
m_FI.m_bAllowZeroLength = FALSE;
This change will disable a workaround that was necessary to avoid a bug
in Visual C++ 4.0. In the download files (DAOTBL.EXE), the workaround code is
conditionally compiled depending on which version you are using to build the
sample. If you do not make the correction given in this section and you run the
application using the Visual C++ 4.1 DLLs, the following exception will be
thrown when you try to create nontext fields:
Couldn't
create field--Exception: Invalid Operation.