📄 vcg13.htm
字号:
<FONT COLOR="#000080"><B>Table 13.3. The CDaoDatabase class members.</B></FONT></CENTER>
<BR>
<CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Member</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Description</I>
</FONT>
<TR>
<TD COLSPAN=2 ALIGN=center VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Data Members</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
m_pWorkspace
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A pointer to the CDaoWorkspace object that contains the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
m_pDAODatabase
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A pointer to the underlying DAO CDaoDatabase object.
</FONT>
<TR>
<TD COLSPAN=2 ALIGN=center VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Construction</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CDaoDatabase
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Constructs the CDaoDatabase object. After construction, you call Open() to connect the object to a database.
</FONT>
<TR>
<TD COLSPAN=2 ALIGN=center VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Attributes</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CanTransact()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns a nonzero value if the database supports transactions.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CanUpdate()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns a nonzero value if the CDaoDatabase object may be updated. If the Database object is read-only, this function returns a zero value.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetConnect()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns the connect string that was used to connect the CDaoDatabase object to a database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetName()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns the name of the database currently in use.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetQueryTimeout()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns the time-out period (in seconds) after which database query operations will time out.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetRecordsAffected()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns a count of the number of records that were affected by the last update, edit, add operation, or call to Execute().
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetVersion()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns the version of the database engine associated with the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
IsOpen()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns a nonzero value if the CDaoDatabase object is currently connected to a database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SetQueryTimeout()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Sets in seconds the time-out period after which database query operations will fail. SetQueryTimeout() affects all subsequent open, add new, update, and delete operations.
</FONT>
<TR>
<TD COLSPAN=2 ALIGN=center VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Operations</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Close()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Closes the database connection.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Create()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Creates the underlying DAO database object and then initializes the CDaoDatabase object.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CreateRelation()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Defines a new relation among the tables in the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
DeleteQueryDef()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Deletes a Querydef object saved in the database's QueryDefs collection.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
DeleteRelation()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Deletes existing relations between tables in the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
DeleteTableDef()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Deletes a table's definition in a database. When that table's definition is deleted, all the table's data is also deleted.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Execute()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Causes the action query to be executed. This query shouldn't return any results. If the executed query returns any results, an exception of type CDaoException is returned.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetQueryDefCount()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns the number of queries defined for the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetQueryDefInfo()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns information about a specified query defined in the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetRelationCount()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns the number of relations defined between tables in the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetRelationInfo()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns information about a specified relation defined between tables in the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetTableDefCount()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns the number of tables defined in the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetTableDefInfo()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns information about a specified table in the database.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Open()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Opens a database and establishes a connection to it.</FONT>
</TABLE></CENTER><BR>
<A NAME="E69E197"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B><I>CDaoTableDef</I></B></FONT></CENTER></H4>
<BR>
<P>The DAO CDaoTableDef object is used to represent the stored definition of a base table or a table that is attached. Each DAO database object has a collection called TableDefs that contains all the saved DAO Tabledef objects.
<BR>
<P>You can manipulate a table definition with CDaoTableDef. Here are some things you can do using CDaoTableDef:
<BR>
<UL>
<LI>In databases, you can examine field and index structures of any local, attached, or external table.
<BR>
<BR>
<LI>You can call the SetConnect() and SetSourceTableName() member functions for attached tables. You also can use the RefreshLink() member function to update your connections to attached tables.
<BR>
<BR>
<LI>You can use the CanUpdate() member function to find out whether you can edit the field definitions in the table.
<BR>
<BR>
<LI>You can get and set validation rules and text using the GetValidationRule(), SetValidationRule(), GetValidationText(), and SetValidationText() member functions.
<BR>
<BR>
<LI>You can create a table-, dynaset-, or snapshot-type CDaoRecordset object by using the Open() member function.
<BR>
<BR>
</UL>
<P>To work with an existing table or create a new table, you will use Tabledef objects. First, construct a CDaoTableDef object. Next, give CDaoTableDef a pointer to a CDaoDatabase object to which the table belongs. Then you have to do one of the following things. What you do depends on what you want to do in your application:
<BR>
<UL>
<LI>Call the Tabledef object's Open() member function, supplying the name of the saved table to use an existing saved table.
<BR>
<BR>
<LI>Call the Tabledef object's Create() member function, supplying the name of the table to create a new table. To add fields and indexes, call CreateField() and CreateIndex().
<BR>
<BR>
<LI>Call the Tabledef object's Append() member function to save the table you opened or created. You do this by appending the table to the database's TableDefs collection. Since Create() opens the Tabledef, it's not necessary to call Open().
<BR>
<BR>
</UL>
<P>It's easy to create tables using Microsoft Access. Open the database in Access, create your tables, and save the database. Using Access for this type manipulation is easier than trying to have your Visual C++ application perform these tasks. Of course, if your application must perform this functionality, and you're reasonably sure that all users of your application won't have Access available, you'll have to perform this task using your Visual C++ application instead of Access.
<BR>
<P>You specify a name for the Tabledef with a dbOpenTable value in the nOpenType parameter when opening a CDaoRecordset.
<BR>
<P>When using a Tabledef object to create a CDaoRecordset object, you might follow the steps just mentioned. After creating the object, construct your Recordset object using a pointer to your Tabledef object when you call CDaoRecordset::Open(). When you pass a Tabledef, it must be open.
<BR>
<P>As with other objects, when you're finished using the Tabledef object, call its Close() member function. After closing the Tabledef object, destroy it.
<BR>
<P>Table 13.4 lists the members of the CDaoTableDef class.
<BR>
<BR>
<P ALIGN=CENTER>
<CENTER>
<FONT COLOR="#000080"><B>Table 13.4. The CDaoTableDef class members.</B></FONT></CENTER>
<BR>
<CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Member</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Description</I>
</FONT>
<TR>
<TD COLSPAN=2 ALIGN=center VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Data Members</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
m_pDatabase
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Contains a pointer to the source database for this table.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
m_pDAOTableDef
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Contains a pointer to the DAO interface underlying this Tabledef object.
</FONT>
<TR>
<TD COLSPAN=2 ALIGN=center VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Construction</I>
</FONT>
<TR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -