QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2662|回复: 0
打印 上一主题 下一主题

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

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>
6 D4 D5 Z1 h+ A( c5 S# O. L1 X<>Creates a new Recordset object and appends it to the Recordsets collection. </P>
( D0 Z- d" I( U2 w<>  </P>
4 i7 y# C) ?- d0 K. s( K$ }<>Syntax </P>
$ v) \; Y* }4 F6 \" ~2 u' X9 }<>  </P># f* m3 Z1 }4 H
<>For Connection and Database objects: </P>
( `* s* E8 d$ j4 }9 }% s( c* X$ v<>  </P>" ~! i; v8 E6 {! Q
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>
. l! Z+ z6 O* W0 a1 @<>  </P>
; N2 J6 b5 l0 x( a( Y+ ~2 I. ^<>For QueryDef, Recordset, and TableDef objects: </P>6 ], g# O+ F( l6 C; n: |
<>  </P>
( g- q8 @2 Z* J; g<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>
( r3 \/ J$ g: w1 k9 {2 ?<>  </P>  O. Z0 ?5 S) O) a
<>The OpenRecordset method syntax has these parts. </P>  r' T' M6 ~, ]: p6 X
<>  </P>7 ~- e4 O7 p. W* q) W9 x, k) a
<>art    Description </P>  d1 I; C+ s- }3 a+ H4 C; @" I6 I
<>recordset       An object variable that represents the Recordset object you wantt to </P>) _3 G3 A+ K$ R' A# y9 Y
<>open. </P>
, m: T1 u5 t1 L<>object  An object variable that represents an existing object from which you </P>
5 w; @6 T+ t( a" C6 s- n( H! I<>want to create the new Recordset. </P>* G: m8 @6 R# d' Q9 r2 s
<>source  A String specifying the source of the records for the new Recordset. </P>
: u8 k- Q4 y; q3 L1 F5 ]. J! L5 H<>The source can be a table name, a query name, or an SQL statement that </P>
7 O" I4 j% ~8 x9 E, q5 M$ D<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>
0 S( H$ Y7 j9 }4 @6 F<>the source can only be a table name. </P>6 e5 x- e* A2 D/ y
<>type    Optional. A constant that indicates the type of Recordset to open, as </P>( _7 D/ }: X3 i" W& |
<>specified in Settings. </P>
$ _1 o8 z1 p( x4 W<>options Optional. A combination of constants that specify characteristics of </P>' {$ u9 ^8 N" Y
<>the new Recordset, as listed in Settings. </P>& c) W, R7 L6 ?6 Y
<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>! _9 |% ]0 \2 J* n. Y
<P>as specified in Settings. </P>- T" U7 \0 [$ |! k3 c4 a
<P>Settings </P>
2 r1 s( h' Y2 |<P>  </P>1 z+ ^5 |0 t+ J5 K# `$ [& _$ C
<P>You can use one of the following constants for the type argument. </P>
3 c/ v  X; M! y' o0 m1 E<P>  </P>8 D5 {2 Y5 v/ W% s
<P>Constant        Description </P>& K9 [* h- _# \$ n* \$ N! F* V% @3 P
<P>  </P>) q) U3 T6 g! L' T) ?
<P>  </P>
, \% ]! }/ i8 m8 q  M<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>
! L5 P# S1 {8 a<P>only). </P>1 G3 Z) M  U) {; v* G2 [
<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>) p' `& o& c8 ^/ c4 j
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>
" U; D  E) ?  }<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>' c1 Z. ^& A* S# C( \
<P>ODBC keyset cursor. </P>1 J: `1 b% e& L
<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>
5 e6 g0 B( R3 Z" Z9 N2 O<P>ODBC static cursor. </P>
4 P0 K* Y- S! r" X  r<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>
7 Y+ m: w7 D0 _" F4 j2 ^5 {% f<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>
! [( S& V* j0 C. J( y6 f2 ?1 y1 h# l<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>4 r9 I3 _% n; F5 `5 N: X2 ~
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>: i) n, k0 L* F
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>( F2 _1 ]6 E# L- F  K- R. B- m! Q. e
<P>y. </P># O/ o* ^$ S( i: e
<P>  </P>
$ z6 n! d# }- \' f2 i/ H<P>You can use a combination of the following constants for the options </P>
5 L, G/ \. W0 A* O) j<P>argument. </P>. I# j, G6 u( K4 s! |6 P
<P>  </P>
1 S1 X$ [/ g: V+ d# W( q! I9 z4 R' z<P>Constant        Description </P>; W$ \( p8 Y6 ~3 _  C* l7 c1 S
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>
9 s; t5 x* c% @3 N+ Z<P>prevents them from editing or deleting existing records (Microsoft Jet </P>
# f9 F2 s$ Z) K1 i2 |<P>dynaset-type Recordset only). </P>" j& }+ N" G1 Y% @
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>/ X- j+ R) r3 ~( r5 y; k/ L
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>; U! R& `4 u/ S
<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>
5 F# f3 X8 [/ r! o% ?% E: {<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>9 P: N5 n2 Z1 A4 O- _" _; i
<P>useful in applications where multiple users have simultaneous read/write </P>
) z6 a* ~& _) @% T. L: `7 L<P>access to the same data. </P>) w* P9 r* [: c5 |9 c' e
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>
3 |) _( P" W; x! c* q  n0 X$ \: j& l) u<P>Jet Recordset objects only). </P>  x, A' U8 N+ ^4 c7 G
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>
7 A9 ~! b6 d" y# E/ |<P>table-type Recordset only). </P>
( _, V- c% o3 i) x<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>; f" ?- T+ Q6 i5 w& K
<P>Recordset only). It is provided only for backward compatibility, and you </P>
5 F! ~& i# ^7 b9 ~<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
+ Q6 P( z( a( O7 m<P>using this option. </P>, e! q  [! _3 D( M2 l; c4 J
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>9 w( G. K& J3 F$ j+ ]$ c
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>0 t( w, N! e* Q$ R; X9 Y/ ^  \& r
<P>option, which is provided only for backward compatibility. </P>
5 ~, h8 ~* a9 [& C6 C<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>; u# }6 I  s, r9 T
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>. K  }, w! J- L) Q
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>
" Y9 Z! k. N5 n6 C; h/ ]5 r<P>not opening a Recordset based on a parameter query. For more information, see </P>2 I% i: o5 n# y$ B" r7 c$ T
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>
) ]- x3 a& u$ {  W( H<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>9 I' j3 a# i, l  i% j0 J
<P>snapshot-type Recordset objects only). </P>8 B$ x3 o3 l6 p& `! Y( X
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P># l6 v3 [6 o. g( `" k) E, u: ]4 o. {. L
<P>snapshot-type Recordset objects only). </P>2 t0 f/ P, O- O3 f9 X- [
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>7 K- m. |# J. [( q4 W9 F
<P>and using both causes an error. Supplying a lockedits argument when options </P>
9 [) A" N; \- Q  g: ~- I7 ?/ m9 t<P>uses the dbReadOnly constant also causes an error. </P>3 c* a; N; Y5 F$ r& K( J9 C
<P>  </P>: \! T! y. ~9 f) q, D. x9 a/ k0 ]
<P>You can use the following constants for the lockedits argument. </P>
# p+ [1 n; }! V; W6 s<P>  </P>
+ G" p5 ~: w" B<P>Constant        Description </P>! v+ r( d) e; V% K3 P) c
<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>! H. h: _1 L* k2 o7 Z  ]! C
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>
) G. q2 N/ S% R: u<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>
* c. }. K" g7 o- Y<P>run-time error occurs. </P>
( P8 P: a1 h1 v: l7 t<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>7 V" i8 N" h5 T! ^
<P>the Recordset in a multiuser environment. The page containing the record </P>
' {- Y. j1 @+ I/ \$ h; E<P>you're editing is locked as soon as you use the Edit method (default for </P>
" M9 Z# I! H/ g+ d<P>Microsoft Jet workspaces). </P>' z" J' \0 g4 i/ Q1 g% `) A, a# L
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>
) p- ^3 f1 n; s+ _<P>Recordset in a multiuser environment. The page containing the record is not </P>
, F6 v; f: m( g  w( Q9 n0 y3 ?<P>locked until the Update method is executed. </P>. @; H/ _, O5 m7 b( a
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>
1 T4 M5 r* g7 O# S& j<P>workspaces only). </P>( |! R* i/ Z7 j. N2 n( f7 L/ p
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>
3 ?; I0 P' t" g% {' Q<P>only). </P>" F  x" b9 V, g% f* _; K6 {
<P>Remarks </P>
' o" U3 g& L  A$ Z! R% ?6 [# }<P>  </P>
) [/ n, z. b% J: O' @, w" z<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>
  l) l8 z( l6 o$ G6 S; _9 H6 x1 e<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>
# o* v5 g- L( B& x  d  W; z$ {9 M<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>
- [$ q/ O' R  Z! i/ [" e# l5 A4 {<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>& N" z, {0 J( W" e
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>
2 a; L0 t! m, w9 Y* ]8 c<P>data source, you must first set the Connect property of the linked table's </P>
: [7 ~  a0 Z8 s5 ?3 m' x<P>database to a valid ODBC connection string. If you only need to make a single </P>
9 A7 x, c$ b0 O) t: [% R<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>
1 W$ u( ^) k  C$ S' W+ {<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>
; f. }* @# W+ h9 t3 Y0 O5 z<P>argument. </P>
% ^- x2 I# x9 p; C<P>  </P>
2 q9 h/ G9 Z  I# V4 g1 V3 v<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>+ a! S! i* J/ v4 t3 A) o* n. z3 m5 ~
<P>is of the same type object. If object </P>5 b% ^+ i+ w- B9 Q$ a" m
<P> refers to a table-type Recordset object, the type of the new object is a </P>1 p/ v1 e& o( {) O
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>( {) X4 b0 b$ _% Z0 L8 D: V
<P>杢ype or ODBCDirect Recordset objects. </P>
9 o7 e! G$ j! \. V' t# e5 O% z<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>
5 B6 b% g; X9 F& t! F<P>select query in the source argument, such as </P>6 z) K. H4 y& }1 k2 b
<P>  </P>4 [9 \. F. O; n  O% @
<P>"SELECT LastName, FirstName FROM Authors </P>" ?$ r( _; F7 e  ?' [( a! ^4 S6 ]
<P>WHERE LastName = 'Smith'; </P>
, }6 ]0 n: t% G<P>SELECT Title, ISBN FROM Titles </P>
4 D# k* B0 y# b' k# A# L<P>WHERE ISBN Like '1-55615-*'" </P>; O7 u: s8 w0 s( p
<P>  </P>3 M/ U! E6 G: z* r- {6 @( \
<P>The returned Recordset will open with the results of the first query. To </P>
; j1 q9 w" }/ J% q; c<P>obtain the result sets of records from subsequent queries, use the </P>$ z: X7 _* L* O
<P>NextRecordset method. </P>) |& R' Z4 v7 ~, ]0 _1 e3 O3 h
<P>  </P>
% M* U- k; |! Q- T5 W<P>Note   You can send DAO queries to a variety of different database servers </P>
* ?4 _* o& a0 k! ?% w! r+ R<P>with ODBCDirect, and different servers will recognize slightly different </P>
1 y! [: j9 p8 A% l: x: J# j<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>7 v/ T9 W+ G5 `& }5 |& N
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>
9 t* B/ d3 Q  R5 h6 T<P>included through the Help menu. Be sure to check the appropriate reference </P>! e, ~7 W& n) }; h% e5 ~" ^
<P>documentation for the SQL dialect of your database server when using either </P>
3 z, t; r6 z) D' |! u<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>
% E  v9 g- S1 Z$ f. u( M1 J: x<P>client/server applications. </P>: ]" e; ?3 J: @$ ]
<P>  </P>
% ~6 r5 ^/ Y2 V9 M) k  H5 ?<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>. v" C  ?9 G0 \/ Q. C% S
<P>trap changes while two or more users are editing or deleting the same record. </P>" U5 h2 J* x/ M9 i: O
<P>For example, if two users start editing the same record, the first user to </P>
% k9 x4 Y! d6 t$ L/ |6 m. {<P>execute the Update method succeeds. When the second user invokes the Update </P>) t; c' s  V" c+ P
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>
: W" R4 R3 ?) o- m9 ^2 E* H: ^# @<P>the Delete method to delete the record, and the first user has already </P>
! o% I% g, n; n0 b5 f) `<P>changed it, a run-time error occurs. </P>
; X% }" M4 \* X. q+ @  I( M9 c<P>  </P>
9 ?6 W# ~! h2 R- s6 g- S. p6 j<P>Typically, if the user gets this error while updating a record, your code </P>
3 `& X' m/ _, ?/ Q- i2 p% [2 u<P>should refresh the contents of the fields and retrieve the newly modified </P>
! }! Q: s- e, F) Y- W3 n6 G<P>values. If the error occurs while deleting a record, your code could display </P>; g, c% G" [( N- ]
<P>the new record data to the user and a message indicating that the data has </P>
- j: U: r8 ~5 o9 ?: F<P>recently changed. At this point, your code can request a confirmation that </P>' h) _% T+ m( U0 {) I
<P>the user still wants to delete the record. </P>7 @: C7 r& n6 f4 f5 C
<P>  </P>0 u/ k* I* f0 d+ L/ h% y) Y
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>
" \$ ?" F' h! m3 o! A  `<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>
4 N; y8 l* f. m3 Q/ v<P>later) table that has an IDENTITY column, otherwise an error may result. </P>+ ~5 f' g  i5 `' [& q7 g
<P>  </P>' O9 k8 G) k* L' i, I7 V3 M# w
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>
9 ^7 s3 I/ S% Y1 F0 `3 y<P>the dbRunAsync constant in the options argument. This allows your application </P>! V$ T  C: a" J+ g$ S8 {! H
<P>to continue processing other statements while the query runs in the </P>
# N( l- q/ m* k& H5 o2 a<P>background. But, you cannot access the Recordset data until the query has </P>& Z$ `. Q3 G; T! K8 }0 v
<P>completed. To determine whether the query has finished executing, check the </P># x) D8 q: t! P, Z- X" P2 C3 h% o( c
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>
3 ?9 _- i/ J6 x9 j9 ^7 V/ X<P>complete than you anticipated, you can terminate execution of the query with </P>
8 y+ M( }, `6 _) U, e- _/ G<P>the Cancel method. </P>
0 S+ h' p5 }* R<P>  </P>
! o- C8 ^7 {" W! w7 ~3 F, y: ^<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
3 `. o; n6 ?. e/ [3 z( L7 p3 I2 h<P>connection is busy with a prior </P>
- U& v  Z/ f! a5 ~- S( o<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>0 L- R; G5 P( r- T& Z' e; S) z) l
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>' Q% ^# s, x% X# L# [" f# L
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>/ i, N2 ^, Q( j  \; `
<P>is opened. </P>) R3 \$ h: n  h6 P/ v  d
<P>  </P>
) A0 n- ~# x0 l- A$ w/ l<P>If you open a Connection object with DefaultCursorDriver set to </P>
* Q! o6 c) e* Y. K% S$ n% _<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>
" i+ z% Q. f! n9 ]2 g, {; o<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>
- n5 v7 ^$ O# q2 J<P>h in the lockedits argument to enable update caching. See the Update method </P>* p2 L) s' V' C. Q
<P>topic for details about how to write changes to disk immediately, or to cache </P>; V9 A8 `- P$ {$ b3 m; Z
<P>changes and write them to disk as a batch. </P>
9 F- G) y: Z& h8 K4 w: Z<P>  </P>
  a4 C* }: i- X3 b: H% C+ v<P>Closing a Recordset with the Close method automatically deletes it from the </P>
* i& y3 w" ?9 K" V$ E& d) @/ w( y% i/ O8 ^, W$ A
<P>Recordsets collection. </P>
4 ~8 t* I0 ~& d9 ~0 c+ S$ d' S<P>  </P>6 g, W, U( f. t2 @
<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
+ p; b, R; k4 l7 ?# z<P>with a non-integer value, and the system parameters specify a non-U.S. </P>
- e: H2 T4 G& b) G<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>
8 l& h- l4 ^# t. v6 @( W<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>( z, U( [, D# p& [4 N+ j3 y9 i5 U
<P>Recordset. This is because during concatenation, the number will be converted </P>
8 I; ~8 ]( Q. Y6 B8 F2 N; c<P>to a string using your system's default decimal character, and SQL only </P>
9 u  \8 f+ k0 b5 H  T* z<P>accepts U.S. decimal characters.</P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-10-9 11:46 , Processed in 3.383565 second(s), 51 queries .

回顶部