Freigeben über


CDaoTableDef Class

Represents the stored definition of a base table or an attached table.

class CDaoTableDef : public CObject

Members

Public Constructors

Name

Description

CDaoTableDef::CDaoTableDef

Constructs a CDaoTableDef object.

Public Methods

Name

Description

CDaoTableDef::Append

Adds a new table to the database.

CDaoTableDef::CanUpdate

Returns nonzero if the table can be updated (you can modify the definition of fields or the table properties).

CDaoTableDef::Close

Closes an open tabledef.

CDaoTableDef::Create

Creates a table which can be added to the database using Append.

CDaoTableDef::CreateField

Called to create a field for a table.

CDaoTableDef::CreateIndex

Called to create an index for a table.

CDaoTableDef::DeleteField

Called to delete a field from a table.

CDaoTableDef::DeleteIndex

Called to delete an index from a table.

CDaoTableDef::GetAttributes

Returns a value that indicates one or more characteristics of a CDaoTableDef object.

CDaoTableDef::GetConnect

Returns a value that provides information about the source of a table.

CDaoTableDef::GetDateCreated

Returns the date and time the base table underlying a CDaoTableDef object was created.

CDaoTableDef::GetDateLastUpdated

Returns the date and time of the most recent change made to the design of the base table.

CDaoTableDef::GetFieldCount

Returns a value that represents the number of fields in the table.

CDaoTableDef::GetFieldInfo

Returns specific kinds of information about the fields in the table.

CDaoTableDef::GetIndexCount

Returns the number of indexes for the table.

CDaoTableDef::GetIndexInfo

Returns specific kinds of information about the indexes for the table.

CDaoTableDef::GetName

Returns the user-defined name of the table.

CDaoTableDef::GetRecordCount

Returns the number of records in the table.

CDaoTableDef::GetSourceTableName

Returns a value that specifies the name of the attached table in the source database.

CDaoTableDef::GetValidationRule

Returns a value that validates the data in a field as it is changed or added to a table.

CDaoTableDef::GetValidationText

Returns a value that specifies the text of the message that your application displays if the value of a Field object does not satisfy the specified validation rule.

CDaoTableDef::IsOpen

Returns nonzero if the table is open.

CDaoTableDef::Open

Opens an existing tabledef stored in the database's TableDef's collection.

CDaoTableDef::RefreshLink

Updates the connection information for an attached table.

CDaoTableDef::SetAttributes

Sets a value that indicates one or more characteristics of a CDaoTableDef object.

CDaoTableDef::SetConnect

Sets a value that provides information about the source of a table.

CDaoTableDef::SetName

Sets the name of the table.

CDaoTableDef::SetSourceTableName

Sets a value that specifies the name of an attached table in the source database.

CDaoTableDef::SetValidationRule

Sets a value that validates the data in a field as it is changed or added to a table.

CDaoTableDef::SetValidationText

Sets a value that specifies the text of the message that your application displays if the value of a Field object does not satisfy the specified validation rule.

Public Data Members

Name

Description

CDaoTableDef::m_pDAOTableDef

A pointer to the DAO interface underlying the tabledef object.

CDaoTableDef::m_pDatabase

Source database for this table.

Remarks

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:

  • Examine the field and index structure of any local, attached, or external table in a database.

  • Call the SetConnect and SetSourceTableName member functions for attached tables, and use the RefreshLink member function to update connections to attached tables.

  • Call the CanUpdate member function to determine if you can edit field definitions in the table.

  • Get or set validation conditions using the GetValidationRule and SetValidationRule, and the GetValidationText and SetValidationText member functions.

  • Use the Open member function to create a table-, dynaset-, or snapshot-type CDaoRecordset object.

    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.

To 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 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.

Inheritance Hierarchy

CObject

CDaoTableDef

Requirements

Header: afxdao.h

See Also

Reference

CObject Class

Hierarchy Chart

CDaoDatabase Class

CDaoRecordset Class