⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcg06.htm

📁 Visual C++与数据库的连接经典实例
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Specifies the beginning of a series of related operations that update data values in one or more persistent objects that underlie one or more Recordset objects.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CommitTrans

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CommitTrans()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Specifies the end of persistent data object update operations that constitute a single transaction and causes the updates to be applied to the table object(s) underlying the Recordset(s).

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Rollback

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

RollBack()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

If the database type supports transactions (ws<I>Name</I>.Transactions = TRUE), cancels the updating of the table objects(s) underlying the Recordset(s) by a preceding CommitTrans statement.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Close

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Close()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Closes the specified CDaoWorkspace and closes all Database objects opened in CDaoWorkspace.</FONT>

</TABLE></CENTER><BR>

<A NAME="E69E134"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Properties of the <I>Database</I> Object</B></FONT></CENTER></H4>

<BR>

<P>The Database object has 11 properties whose values you can read to determine the characteristics of the database as a whole. The majority of these properties are read-only at all times. Table 6.5 lists the properties of the Database object in the approximate order of the frequency with which you're likely to use them. The last five properties listed aren't supported by MFC's implementation of DAO. You can access them by calling DAO directly, as noted in Visual C++ 4's Technical Note 54.

<BR>

<BR>

<P ALIGN=CENTER>

<CENTER>

<FONT COLOR="#000080"><B>Table 6.5. Properties of the Database object.</B></FONT></CENTER>

<BR>



<CENTER><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Property</I>

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>CDaoDatabase</I><I> Member </I><I>Function</I>

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Purpose/Parameters</I>

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Name

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

GetName()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Returns a CString pointer that contains a well-formed path to the open database and the name of the open database.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Connect

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

GetConnect()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Returns a CString pointer that contains the value of the string used to establish a connection to the database. The Connect property is an empty string for Access databases.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Updatable

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CanUpdate()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Indicates if the database has been opened in read-write (TRUE) or read-only (FALSE) mode. The Updatable property itself is read-only. (See the section &quot;Connecting to an Existing Jet Database.&quot;)

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Transactions

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CanTransact()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Indicates whether the database supports the Rollback transaction processing statement that lets you undo a group of changes to data values in the database's tables (TRUE). Access and most client-server databases support the rolling back of transactions.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

QueryTimeout

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

GetQueryTimeout()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Specifies or indicates the length of time in seconds before a time-out error occurs when you execute a query against a client-server database via an ODBC driver. The default value is 60 seconds.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Version

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

GetVersion()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Returns an Integer flag that indicates the version number of the Jet engine that created the database (see Table 6.4).

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CollatingOrder

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Not directly supported

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

An Integer flag that indicates the language whose rules are used by the database to sort text fields. The default value is 256 (for English and most Western European languages). The CollatingOrder property is read-only, except when you use the CreateDatabase() and CompactDatabase() methods. (These two methods expect the CollatingOrder flag to be a long integer.)

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Replicable

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Not directly supported

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

When set to TRUE, creates a replicable database from which you can create additional replicas for distribution to users. Once this is made replicable, you can't set the Replica property to FALSE. Returns TRUE for a replicable database.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

DesignMasterID

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Not directly supported

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

A globally-unique ID (GUID) that identifies the replicable database from which user replicas are created.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

ReplicaID

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Not directly supported

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

A GUID that identifies each database replica.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

V1xNullBehavior

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Not directly supported

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

If set to TRUE, zero-length strings (&quot;&quot;) in Jet (Access) 1.x fields of the Text and Memo type are converted to Null values.</FONT>

</TABLE></CENTER><BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE><B>NOTE</B>

<BR>

<BR>The replication properties in Table 6.5&#151;Replicable, DesignMasterID, and ReplicaID&#151;don't appear in the Properties list of the online help topic for the Database object. Replication is limited to Jet 3.0 (Access 7.0) databases. The KeepLocal property applies to objects contained in a replicable database, not to the Database object itself.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<BR>

<A NAME="E69E135"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Methods Applicable to the <I>Database</I> Object</B></FONT></CENTER></H4>

<BR>

<P>The Database object has many more methods than properties. Many of Visual C++ DAO's methods of the Database object are now methods of the CDaoWorkspace, CDaoTableDef, CDaoRecordset, and CDaoQueryDef objects. The OpenRecordset and CreateQueryDef methods are Database object methods, because data objects of these types can (and usually do) act on more than one table of the Database object. However, these two methods are attached to different DAO MFC objects (see Table 6.6). The methods that you can apply to Database objects are listed in Table 6.6. They are listed in groups of related methods rather than in alphabetical order. The DAO MRC class is also listed because it varies with each of these methods.

<BR>

<BR>

<P ALIGN=CENTER>

<CENTER>

<FONT COLOR="#000080"><B>Table 6.6. Methods applicable to the Database object.</B></FONT></CENTER>

<BR>



<CENTER><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Method</I>

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>DAO Class and Member </I><I>Function</I>

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Purpose/Parameters</I>

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CreateTableDef

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CDaoTableDef::Create()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Used in a Set statement to create a new persistent TableDef object that defines a newly created table in a database.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CreateRelation

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

CDaoDatabase::CreateRelation()

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Used in a Set statement to establish a relationship between the primary key field of a base table and the foreign key field of a related table.

</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

OpenRecordset

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -