Home | Overview | How Do I | FAQ | Sample | Tutorial | ODBC Driver List
This article explains how to access the “collections” in which DAO keeps active DAO objects at all levels of the DAO object hierarchy. The article also explains how the collections are exposed in MFC. Topics covered include:
In DAO, each object in the object hierarchy maintains one or more "collections" of subordinate objects. For example, the Microsoft Jet database engine maintains a collection of open workspaces. Each workspace object maintains a collection of open databases (and other collections, related to security). And so on. For a list of the DAO objects and the collections they house, see the topic "Data Access Objects and Collections Reference" in DAO Help.
In the MFC DAO classes, MFC doesn't maintain a collection (such as a CObArray) of C++ objects parallel to the underlying DAO collection. Rather, MFC supplies member functions and/or data members through which you can access the underlying collection itself in DAO, where the DAO collections are stored. For example, class CDaoWorkspace supplies the GetWorkspaceCount member function to determine how many workspaces are in the database engine's Workspaces collection and the GetWorkspaceInfo member function to examine information about any workspace in the collection.
In general, the MFC DAO classes supply similar functions for all relevant DAO collections. The one significant exception is the Recordsets collection of the database object. MFC does not supply GetRecordsetCount and GetRecordsetInfo member functions in class CDaoDatabase. When you work with recordsets, you always have an explicit MFC CDaoRecordset object in your application. It's up to you to keep track of which recordsets you have open.
The first element in a DAO collection, at element 0, is the default element of the collection. In particular, DAO's default workspace is element 0 in the Workspaces collection. Collections are zero-based.
The following procedure uses the TableDefs collection of a CDaoDatabase object to illustrate the general process for accessing objects in a DAO collection.
To access the TableDefs collection (for example)
For an example, see the LISTVIEW.CPP file in the MFC Database sample DAOVIEW. For a procedure, see the article DAO Collections: Obtaining Information About DAO Objects.
To obtain information about the objects in a collection, you call a GetXInfo member function of the appropriate class. This function returns an object of one of the CDaoXInfo structures listed in the table Classes for Obtaining Information About DAO Objects in the article DAO Collections: Obtaining Information About DAO Objects. In general, there is a CDaoXInfo structure associated with each DAO object. These structures are commonly referred to as the MFC DAO “information structures.”
A typical information structure looks something like this:
struct CDaoDatabaseInfo
{
CString m_strName; // Primary
BOOL m_bUpdatable; // Primary
BOOL m_bTransactions; // Primary
CString m_strVersion; // Secondary
long m_lCollatingOrder; // Secondary
short m_nQueryTimeout; // Secondary
CString m_strConnect; // All
};
For detailed descriptions of the structure members, see the individual structure in the Class Library Reference. Structures are listed in the table Classes for Obtaining Information About DAO Objects in the article DAO Collections: Obtaining Information About DAO Objects.
The notations “Primary,” “Secondary,” and “All” indicate which MFC DAO structure members are filled when you call a function such as GetDatabaseInfo. You can specify that you want just primary information, both primary and secondary information, or all information. Some structures don’t include anything under the All designation.
Caution Using the Secondary and All options can be slow. In general, Primary is faster than Secondary, and Secondary is faster than All. Don’t use All unless you must.
For more information about using GetTableDefCount, GetTableDefInfo, and similar functions, see the article DAO Collections: Obtaining Information About DAO Objects.
For general information about the DAO collections, see the topic "Data Access Objects and Collections Reference" in DAO Help.
See Also DAO: Where Is...