韩冰 发表于 2005-1-26 12:38

怎样用ADO打开一个带密码的Access库?

<P>  </P>
<P>Creates a new Recordset object and appends it to the Recordsets collection. </P>
<P>  </P>
<P>Syntax </P>
<P>  </P>
<P>For Connection and Database objects: </P>
<P>  </P>
<P>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>
<P>  </P>
<P>For QueryDef, Recordset, and TableDef objects: </P>
<P>  </P>
<P>Set recordset = object.OpenRecordset (type, options, lockedits) </P>
<P>  </P>
<P>The OpenRecordset method syntax has these parts. </P>
<P>  </P>
<P>Part    Description </P>
<P>recordset       An object variable that represents the Recordset object you wantt to </P>
<P>open. </P>
<P>object  An object variable that represents an existing object from which you </P>
<P>want to create the new Recordset. </P>
<P>source  A String specifying the source of the records for the new Recordset. </P>
<P>The source can be a table name, a query name, or an SQL statement that </P>
<P>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>
<P>the source can only be a table name. </P>
<P>type    Optional. A constant that indicates the type of Recordset to open, as </P>
<P>specified in Settings. </P>
<P>options Optional. A combination of constants that specify characteristics of </P>
<P>the new Recordset, as listed in Settings. </P>
<P>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>
<P>as specified in Settings. </P>
<P>Settings </P>
<P>  </P>
<P>You can use one of the following constants for the type argument. </P>
<P>  </P>
<P>Constant        Description </P>
<P>  </P>
<P>  </P>
<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>
<P>only). </P>
<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>
<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>
<P>ODBC keyset cursor. </P>
<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>
<P>ODBC static cursor. </P>
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>
<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>
<P>y. </P>
<P>  </P>
<P>You can use a combination of the following constants for the options </P>
<P>argument. </P>
<P>  </P>
<P>Constant        Description </P>
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>
<P>prevents them from editing or deleting existing records (Microsoft Jet </P>
<P>dynaset-type Recordset only). </P>
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>
<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>
<P>useful in applications where multiple users have simultaneous read/write </P>
<P>access to the same data. </P>
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>
<P>Jet Recordset objects only). </P>
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>
<P>table-type Recordset only). </P>
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>
<P>Recordset only). It is provided only for backward compatibility, and you </P>
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
<P>using this option. </P>
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>
<P>option, which is provided only for backward compatibility. </P>
<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>
<P>not opening a Recordset based on a parameter query. For more information, see </P>
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>
<P>snapshot-type Recordset objects only). </P>
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>
<P>snapshot-type Recordset objects only). </P>
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>
<P>and using both causes an error. Supplying a lockedits argument when options </P>
<P>uses the dbReadOnly constant also causes an error. </P>
<P>  </P>
<P>You can use the following constants for the lockedits argument. </P>
<P>  </P>
<P>Constant        Description </P>
<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>
<P>run-time error occurs. </P>
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>
<P>the Recordset in a multiuser environment. The page containing the record </P>
<P>you're editing is locked as soon as you use the Edit method (default for </P>
<P>Microsoft Jet workspaces). </P>
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>
<P>Recordset in a multiuser environment. The page containing the record is not </P>
<P>locked until the Update method is executed. </P>
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>
<P>workspaces only). </P>
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>
<P>only). </P>
<P>Remarks </P>
<P>  </P>
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>
<P>data source, you must first set the Connect property of the linked table's </P>
<P>database to a valid ODBC connection string. If you only need to make a single </P>
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>
<P>argument. </P>
<P>  </P>
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>
<P>is of the same type object. If object </P>
<P> refers to a table-type Recordset object, the type of the new object is a </P>
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>
<P>杢ype or ODBCDirect Recordset objects. </P>
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>
<P>select query in the source argument, such as </P>
<P>  </P>
<P>"SELECT LastName, FirstName FROM Authors </P>
<P>WHERE LastName = 'Smith'; </P>
<P>SELECT Title, ISBN FROM Titles </P>
<P>WHERE ISBN Like '1-55615-*'" </P>
<P>  </P>
<P>The returned Recordset will open with the results of the first query. To </P>
<P>obtain the result sets of records from subsequent queries, use the </P>
<P>NextRecordset method. </P>
<P>  </P>
<P>Note   You can send DAO queries to a variety of different database servers </P>
<P>with ODBCDirect, and different servers will recognize slightly different </P>
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>
<P>included through the Help menu. Be sure to check the appropriate reference </P>
<P>documentation for the SQL dialect of your database server when using either </P>
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>
<P>client/server applications. </P>
<P>  </P>
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>
<P>trap changes while two or more users are editing or deleting the same record. </P>
<P>For example, if two users start editing the same record, the first user to </P>
<P>execute the Update method succeeds. When the second user invokes the Update </P>
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>
<P>the Delete method to delete the record, and the first user has already </P>
<P>changed it, a run-time error occurs. </P>
<P>  </P>
<P>Typically, if the user gets this error while updating a record, your code </P>
<P>should refresh the contents of the fields and retrieve the newly modified </P>
<P>values. If the error occurs while deleting a record, your code could display </P>
<P>the new record data to the user and a message indicating that the data has </P>
<P>recently changed. At this point, your code can request a confirmation that </P>
<P>the user still wants to delete the record. </P>
<P>  </P>
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>
<P>later) table that has an IDENTITY column, otherwise an error may result. </P>
<P>  </P>
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>
<P>the dbRunAsync constant in the options argument. This allows your application </P>
<P>to continue processing other statements while the query runs in the </P>
<P>background. But, you cannot access the Recordset data until the query has </P>
<P>completed. To determine whether the query has finished executing, check the </P>
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>
<P>complete than you anticipated, you can terminate execution of the query with </P>
<P>the Cancel method. </P>
<P>  </P>
<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
<P>connection is busy with a prior </P>
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>
<P>is opened. </P>
<P>  </P>
<P>If you open a Connection object with DefaultCursorDriver set to </P>
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>
<P>h in the lockedits argument to enable update caching. See the Update method </P>
<P>topic for details about how to write changes to disk immediately, or to cache </P>
<P>changes and write them to disk as a batch. </P>
<P>  </P>
<P>Closing a Recordset with the Close method automatically deletes it from the </P>

<P>Recordsets collection. </P>
<P>  </P>
<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
<P>with a non-integer value, and the system parameters specify a non-U.S. </P>
<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>
<P>Recordset. This is because during concatenation, the number will be converted </P>
<P>to a string using your system's default decimal character, and SQL only </P>
<P>accepts U.S. decimal characters.</P>
页: [1]
查看完整版本: 怎样用ADO打开一个带密码的Access库?