📄 vcg06.htm
字号:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CDaoRecordset::Open()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Used in a Set statement to create a new Recordset object of the Table, Dynaset, or Snapshot type. OpenRecordset is the most commonly used method of the Database object.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Refresh
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CDaoRecordset::Requery()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Updates collections of persistent objects of the database, such as the QueryDefs and TableDefs collections, to reflect the current content of the collection.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CreateQueryDef
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CDaoQueryDef::Create()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Used in a Set statement to create a new persistent QueryDef object based on an SQL statement.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Execute
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CDaoQueryDef::Execute()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Executes a QueryDef or SQL statement that doesn't return records, such as an UPDATE, INSERT, or DELETE query. Access uses the term <I>action </I><I>query</I> to indicate a query that doesn't return records.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CreateProperty
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Not directly supported
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Adds a user-defined property of a name you specify to the Database object and sets the data type and the initial value of the user-defined property.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
MakeReplica
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Not directly supported
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Creates a user replica from the design-master replica of a replicable database. You specify the location and filename of the new replica and whether the replica is updatable or read-only with arguments of the MakeReplica method.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Synchronize
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Not directly supported
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Synchronizes the Database object with changes made to a replica of the database, which is specified by location and filename. You can receive changes, export changes, or perform bidirectional updates (the default), depending on the value of the argument.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Close
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
CDaoDatabase::Close()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Closes a Database object and frees resources consumed by the object.</FONT>
</TABLE></CENTER><P>All member objects of the CDaoDatabase object must be closed before you can close the CDaoDatabase object. If you've declared your CDaoDatabase object variable with local scope, you don't need to use the Close() function, because the CDaoDatabase object and its member object are closed by the destructor when the variables go out of scope at the termination of the procedure in which the variables were declared.
<BR>
<BR>
<A NAME="E69E136"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Connecting to an Existing Jet Database</B></FONT></CENTER></H4>
<BR>
<P>Here is the full, generalized syntax of the Open() function that you use to connect to and create a named reference to an existing database:
<BR>
<PRE>
<FONT COLOR="#000080">CDaoDatabase::Open(
LPCTSTR <I>lpszName</I>,
BOOL <I>bExclusive</I> = FALSE,
BOOL <I>bReadOnly</I> = FALSE,
LPCTSTR <I>lpszConnect</I> = _T("") );</FONT></PRE>
<P>Table 6.7 lists the arguments used with the Open() function.
<BR>
<BR>
<P ALIGN=CENTER>
<CENTER>
<FONT COLOR="#000080"><B>Table 6.7. The arguments of the Open() function.</B></FONT></CENTER>
<BR>
<CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Argument</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Purpose</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
lpszName
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Specifies the well-formed path (drive and directory) to the location of the database file(s), except for ODBC data sources. Only the path to the directory that contains the table and index files is required when you connect to dBASE, FoxPro, and Paradox databases. All the files of these databases must be located in the same directory. You can use the uniform naming convention (UNC) to specify database files that are located on a network server. For example, you can use \\\\Servername{\\Folder\\Sharename as the value. For databases connected through the ODBC API, use the data source name (DSN) of an ODBC data source that is registered in your registry or your \WINDOWS\ODBC.INI file. Alternatively, you can leave this argument empty for ODBC databases and provide the required connect string in the <I>lpszConnect</I> argument.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
bExclusive
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
An Integer flag that determines if the database is to be opened in exclusive (TRUE) or shared (FALSE) mode. The default value is FALSE.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
bReadonly
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
An Integer flag that determines if the database is to be opened in read-only (TRUE) or read-write (FALSE) mode. The default value is FALSE.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
lpszConnect
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A pointer to a character string whose content depends on the type of database you intend to open. The <I>lpszConnect</I> argument isn't used for Jet databases, but it's required for other desktop databases. The <I>lpszConnect</I> argument is necessary to prevent the Login dialog of ODBC databases from appearing when you specify an ODBC data source.</FONT>
</TABLE></CENTER><P>The following code fragment opens the Jet 2.5 Stdreg32.mdb sample database included with Visual C++ 4.0 for exclusive, read-only access:
<BR>
<PRE>
<FONT COLOR="#000080">CDaoDatabase db;
db.Open("Stdreg32.mdb", TRUE, TRUE)</FONT></PRE>
<P>The following code creates a new Jet 2.5 (Access 2.0) database in the current directory:
<BR>
<PRE>
<FONT COLOR="#000080">CDaoDatabase db;
db.Create("new.mdb",_
dbLangGeneral, dbVersion25)</FONT></PRE>
<P>To make a new Jet database useful, you must add tables to the database's TableDefs collection and then add fields and indexes to each table's Fields and Index collections. The following sections describe the process more fully.
<BR>
<BR>
<A NAME="E68E40"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Using the <I>TableDefs</I> Collection and <I>TableDef</I> Objects</B></FONT></CENTER></H3>
<BR>
<P>The DAO TableDefs collection contains a member TableDef object for each table in the database. TableDefs are handled with the CDaoTableDef DAO MFC class. TableDef members qualify as objects because each TableDef has its own set of properties and has methods that are common to all members of the collection. The properties of the TableDef object describe each table in the database. Table 6.8 lists the properties of the TableDef object in the order in which the values might appear in a data dictionary.
<BR>
<BR>
<P ALIGN=CENTER>
<CENTER>
<FONT COLOR="#000080"><B>Table 6.8. Properties of the TableDef 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>Member Function</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Description</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 object that contains the name of the table.
</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 object that contains the connect string used to attach tables to a Jet database. You can attach tables only to Jet .MDB databases.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SourceTableName
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetSourceTableName()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns a CString object that contains the name of an attached table. You can use the Name property to create an alias for an attached table.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
ValidationRule
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetValidationRule()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns a CString object that contains a rule for maintaining table-level domain integrity, expressed as a string containing the WHERE criterion of a Jet SQL SELECT statement (without the WHERE SQL reserved word), such as InvoiceDate >= OrderDate. InvoiceDate and OrderDate are fields of the same table. Multiple validation rules must use the SQL AND conjunction. (Jet 2.5 and 3.0 databases only.)
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
ValidationText
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
GetValidationText()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Returns a CString object that contains the message that will appear if an attempted update to the table would violate the Valid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -