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

📄 vcg13.htm

📁 Visual C++与数据库的连接经典实例
💻 HTM
📖 第 1 页 / 共 5 页
字号:

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

Append()

</FONT>

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

Adds a new table to the database.

</FONT>

<TR>

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

CDaoTableDef()

</FONT>

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

Constructs a CDaoTableDef object.

</FONT>

<TR>

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

Close()

</FONT>

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

Closes an open Tabledef.

</FONT>

<TR>

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

Create()

</FONT>

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

Creates a table that can be added to the database using the Append() function.

</FONT>

<TR>

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

Open()

</FONT>

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

Opens an existing Tabledef stored in the database's TableDefs collection.

</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>

CanUpdate()

</FONT>

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

Determines whether a table can be updated. If CanUpdate() returns a nonzero value, the table can be updated.

</FONT>

<TR>

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

GetAttributes()

</FONT>

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

Determines the characteristics of a CDaoTableDef object.

</FONT>

<TR>

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

GetConnect()

</FONT>

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

Gets information about the source of a table.

</FONT>

<TR>

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

GetDateCreated()

</FONT>

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

Gets the creation date and time for the base table underlying a CDaoTableDef object.

</FONT>

<TR>

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

GetDateLastUpdated()

</FONT>

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

Gets the date and time of the last change to the base table.

</FONT>

<TR>

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

GetFieldCount()

</FONT>

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

Determines the number of fields in the table.

</FONT>

<TR>

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

GetFieldInfo()

</FONT>

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

Obtains information about fields in the table.

</FONT>

<TR>

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

GetIndexCount()

</FONT>

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

Determines the number of indexes to the table.

</FONT>

<TR>

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

GetIndexInfo()

</FONT>

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

Obtains information about indexes to the table.

</FONT>

<TR>

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

GetName()

</FONT>

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

Obtains the user-defined table name.

</FONT>

<TR>

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

GetRecordCount()

</FONT>

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

Determines the number of records in the table.

</FONT>

<TR>

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

GetSourceTableName()

</FONT>

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

Obtains the name of the attached table in the source database.

</FONT>

<TR>

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

GetValidationRule()

</FONT>

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

Obtains the validation rule that is used to validate the data in a field as it is changed or added to a table.

</FONT>

<TR>

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

GetValidationText()

</FONT>

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

Obtains a value that specifies the text of the message that your application displays if the value of a Field object doesn't satisfy the specified validation rule.

</FONT>

<TR>

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

IsOpen()

</FONT>

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

Determines whether a table is open or not. Returns a zero value if the table isn't open.

</FONT>

<TR>

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

SetAttributes()

</FONT>

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

Sets the value that is used to change one or more characteristics of a CDaoTableDef object.

</FONT>

<TR>

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

SetConnect()

</FONT>

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

Sets values that are used in the connection to the table.

</FONT>

<TR>

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

SetName()

</FONT>

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

Sets the name of the table.

</FONT>

<TR>

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

SetSourceTableName()

</FONT>

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

Sets the source table's name.

</FONT>

<TR>

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

SetValidationRule()

</FONT>

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

Sets a validation rule. The validation rule is used every time data in a field is changed (or added) to a table.

</FONT>

<TR>

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

SetValidationText()

</FONT>

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

Sets the message that is to be displayed whenever data doesn't meet the specifications described by the validation rule.

</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>

CreateField()

</FONT>

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

Creates a field for a table.

</FONT>

<TR>

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

CreateIndex()

</FONT>

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

Creates an index for a table.

</FONT>

<TR>

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

DeleteField()

</FONT>

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

Deletes a field from a table.

</FONT>

<TR>

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

DeleteIndex()

</FONT>

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

Deletes an index from a table.

</FONT>

<TR>

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

RefreshLink()

</FONT>

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

Updates the connection information for an attached table.</FONT>

</TABLE></CENTER><BR>

<A NAME="E69E198"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B><I>CDaoQueryDef</I></B></FONT></CENTER></H4>

<BR>

<P>A Querydef is a query definition that is usually (but doesn't have to be) stored or saved in a database. Access databases often have query definitions stored in them. Querydefs consist of SQL statements that describe a query, the query's properties (such as the date it was created), and the time-out value. Since Querydefs don't need to be stored in a database, they can also be temporary objects. It isn't unusual for a Visual C++ front-end application to create a temporary Querydef object.

<BR>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE><B>NOTE</B>

<BR>

<BR>Querydefs are always more efficient if they're stored in the database. Any Querydef that is to be executed frequently should always be saved in the database.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<P>The CDaoDatabase object will maintain a collection, the QueryDefs collection, containing the object's saved Querydefs.

<BR>

<P>You can use CDaoQueryDef to work with saved queries and to create a new saved or temporary query. You would use CDaoQueryDef in the following way. First, you would create and construct your CDaoQueryDef object. This object would be supplied with the pointer to your CDaoDatabase object to which the query will belong. Next, you must do one of the following:

<BR>

<UL>

<LI>When using an existing, saved query, you would call CDaoQueryDef's Open() member function. In the call to Open(), you must provide the name of the saved query.

<BR>

<BR>

<LI>When creating a new query that is to be saved, you would call CDaoQueryDef's Create() member function. In the call to Create(), you would provide the name of the query. You would then have to call the Append() member function to save the query. You save the query by appending it to the database's QueryDefs collection. Since the Create() function opens the query, it's not necessary to call the Open() function.

<BR>

<BR>

<LI>When creating a new, temporary query, you would call the Create() member function. Use an empty string as the name for the query, and don't call Append() to save the query.

<BR>

<BR>

</UL>

<P>After you've finished using the Querydef object, call the Close() member function to close it. As soon as the Querydef is closed, destroy the CDaoQueryDef object.

<BR>

<P>You can easily create Querydef objects using Microsoft Access. Open the database, design your query, and save it. Your Visual C++ database application can then use the query.

<BR>

<P>A Querydef object is used for either of the following:

<BR>

<UL>

<LI>You can use it to create a CDaoRecordset object.

<BR>

<BR>

<LI>You can call the object's Execute() member function to directly execute either an action query or an SQL pass-through query.

<BR>

<BR>

</UL>

<P>All types of queries can be used as Querydef objects. For example, queries can take the form of select, action, crosstab, delete, update, append, make-table, data definition, SQL pass-through, union, or bulk queries. The SQL statement that makes up the query determines the type of query.

<BR>

<P>See the Execute() and GetType() member functions in the Visual C++ Books Online for more information about queries. A query that would return a set of rows (as a recordset) is usually in the form of SELECT <I>rows</I> FROM <I>table</I> <I>types</I> of SQL statements.

<BR>

<P>When you use a Querydef to create a CDaoRecordset object, you create (or open) a Querydef. Then a CDaoRecordset object would be created and passed a pointer to your Querydef object. This pointer would be passed in the call to CDaoRecordset::Open(). The Querydef you pass must itself be open. If the Querydef isn't open, it can't be used to create a recordset.

<BR>

<P>You would use a Querydef object to gain access to the native SQL dialect for an external (non-Access) database. If you needed to create a Transact SQL query (Transact is the version of SQL used by Microsoft SQL Server), you would create the query and store it as a Querydef object.

<BR>

<P>Table 13.5 lists the members of the CDaoQueryDef class.

<BR>

<BR>

<P ALIGN=CENTER>

<CENTER>

<FONT COLOR="#000080"><B>Table 13.5. The CDaoQueryDef 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>

⌨️ 快捷键说明

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