CDaoTableDef

A CDaoTableDef object represents the stored definition of a base table or an attached table. Each DAO database object maintains a collection, called TableDefs, that contains all saved DAO tabledef objects.

You manipulate a table definition using a CDaoTableDef object. For example, you can:

Note   The DAO database classes are distinct from the MFC database classes based on Open Database Connectivity (ODBC). All DAO database class names have the “CDao” prefix. You can still access ODBC data sources with the DAO classes; the DAO classes generally offer superior capabilities because they are specific to the Microsoft Jet database engine.

Use tabledef objects either to work with an existing table or to create a new table:

  1. In all cases, first construct a CDaoTableDef object, supplying the a pointer to a CDaoDatabase object to which the table belongs.

  2. Then do the following, depending on what you want:
    • To use an existing saved table, call the tabledef object’s Open member function, supplying the name of the saved table.

    • To create a new table, call the tabledef object’s Create member function, supplying the name of the table. Call CreateField and CreateIndex to add fields and indexes to the table.

    • Call Append to save the table by appending it to the database’s TableDefs collection. Create puts the tabledef into an open state, so after calling Create you do not call Open.

Tip   The easiest way to create saved tables is to create them and store them in your database using Microsoft Access. Then you can open and use them in your MFC code.

To use the tabledef object you have opened or created, create and open a CDaoRecordset object, specifying the name of the tabledef with a dbOpenTable value in the nOpenType parameter.

To use a tabledef object to create a CDaoRecordset object, you typically create or open a tabledef as described above, then construct a recordset object, passing a pointer to your tabledef object when you call CDaoRecordset::Open. The tabledef you pass must be in an open state. For more information, see class CDaoRecordset.

When you finish using a tabledef object, call its Close member function; then destroy the tabledef object.

For more information on tabledefs, see the articles DAO Tabledef and DAO Tabledef: Using Tabledefs in Visual C++ Programmer's Guide.

#include <afxdao.h>

Class MembersBase ClassHierarchy Chart

Samples   MFC Sample DAOVIEWMFC Sample DAOTABLE

See Also   CDaoDatabase, CDaoRecordset