QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |正序浏览
|招呼Ta 关注Ta
<>  </P>, p; |9 ]7 k: s1 f* C) h0 ]
<>Creates a new Recordset object and appends it to the Recordsets collection. </P>0 u6 H- ?  t) V- G
<>  </P>! ]1 v. x, }! q7 V. d
<>Syntax </P>
/ {+ x( U: Z% i( B1 t, I7 Q<>  </P>' Z& O" R) E# M0 ?
<>For Connection and Database objects: </P>
) Z& m9 v" r) R9 D<>  </P>
+ _5 ], x- u5 _; c1 w. |# U<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>4 `: m7 a$ t6 }" @% Z1 l$ q
<>  </P>
. s) ~1 ?2 q7 i0 o- M/ @: e) J( [* l  f<>For QueryDef, Recordset, and TableDef objects: </P>2 N, n% V! r( R! |& W
<>  </P>
4 [4 n6 p5 y: f7 s% }4 ^<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>
& N: N8 n# x6 q/ N# g<>  </P>
! F$ W4 D; p* n# U  F7 j: i- F9 p<>The OpenRecordset method syntax has these parts. </P>; i5 y0 Z  _8 ?; w
<>  </P>
* c+ ]8 D- B* f<>art    Description </P>
. c$ t+ _9 g) t# M$ Z9 y1 y+ W<>recordset       An object variable that represents the Recordset object you wantt to </P>
/ D; {% R' O! {' ^8 V3 w( j<>open. </P>
) ~, j- s3 e( t# o/ b<>object  An object variable that represents an existing object from which you </P>
" X$ {/ W" a# {: n<>want to create the new Recordset. </P>
- m9 ^8 u. |5 |. M9 E. P4 z<>source  A String specifying the source of the records for the new Recordset. </P>* L# H8 w8 G% G2 l9 v( h6 u& }
<>The source can be a table name, a query name, or an SQL statement that </P>/ J* h- \1 W1 y6 r
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>1 ]4 N9 r+ Q& l6 U" }8 y
<>the source can only be a table name. </P>
' g8 Q# u2 s8 l- U' [8 a$ O<>type    Optional. A constant that indicates the type of Recordset to open, as </P>9 j/ Y4 x5 Z: }) |
<>specified in Settings. </P>" v* H1 Z6 ]4 K1 r5 G- G; {# n& O
<>options Optional. A combination of constants that specify characteristics of </P>- F" t" B7 c7 {0 ]+ N5 ?
<>the new Recordset, as listed in Settings. </P>: D* b8 g+ N& V' s
<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>
7 w0 |" S* g' v+ {2 a* o<P>as specified in Settings. </P>
3 O, ]: ?  a& ]! f0 z/ c" ~<P>Settings </P>
/ Z, E. d" e. R9 h. \<P>  </P>
5 s& x3 s/ L' O" t! \7 Y. n0 b<P>You can use one of the following constants for the type argument. </P>
" S; b6 v4 \: g6 L- N* [<P>  </P>
" J- s3 _- I( N2 \' G2 Y( \<P>Constant        Description </P>
1 @4 J8 m8 u5 b% ^& D7 s<P>  </P>2 h1 n4 r6 D$ c" }3 O8 K
<P>  </P>4 k0 `3 N4 x) M; @
<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>
8 {# D7 C+ q) K) l: ?' S<P>only). </P>
5 c4 I! c- p8 `: u! M4 T: `<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>6 u$ ^/ t6 [! i# W
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>5 C: |' P" u( G! r9 Y+ k5 K4 J
<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>
1 ^. ]2 n' f1 Z, w3 ]<P>ODBC keyset cursor. </P>
: k6 \, j7 R2 j4 C$ ^( C<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>
# _5 C: M' e4 ]- H% A* Y: |9 P<P>ODBC static cursor. </P>+ c( t' ^% W( F% T! d, I( ~
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>4 _3 ]2 f+ N) X. [" e) Y7 t
<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>
/ j. D; Z8 G3 ^<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>, y- j* f; w$ r- I6 |9 {, u
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>
. Y0 a4 U) E- C, @) c  k7 Q1 i<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>
5 ~1 h! `1 X  p, m<P>y. </P>
: F7 f7 G% Y2 |. f) k5 S<P>  </P>' ]7 u) \& H) a7 \6 V6 k- L2 l
<P>You can use a combination of the following constants for the options </P>4 b5 h& A% _' ~2 t6 g) P1 ~
<P>argument. </P>+ w2 e: g8 T- S# r8 l6 a
<P>  </P>0 }  g2 r7 o' `# z/ k8 [+ M
<P>Constant        Description </P>3 S; ?. \  \( b8 U
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>
) ~8 C3 R1 k( {. M  e: @<P>prevents them from editing or deleting existing records (Microsoft Jet </P>; ?% T' c8 D: b) Z* L5 ~% j
<P>dynaset-type Recordset only). </P>9 J" M* n! P! L1 S. t
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>: P1 ~! f9 \$ m# V9 R
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>
. Y/ r, J8 \: m' h* W3 s! W: K0 ^, Z. w<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>
3 ~) q5 j6 a; _. Q/ c<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>
6 W# V  j8 l9 N9 Z- `0 O" \<P>useful in applications where multiple users have simultaneous read/write </P>2 a2 A# B- B8 K$ q& E& J
<P>access to the same data. </P>; c3 a7 c! z; N$ m6 t1 G% s
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>* O2 `% M; [- L* n! U- W
<P>Jet Recordset objects only). </P>4 ~' Z) Z; t1 u) ]2 z
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>
' K. k; e$ Q0 r: [; u4 \<P>table-type Recordset only). </P>
6 f$ |/ N9 H4 B<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>
: L4 _/ ^* h9 Z' s2 r<P>Recordset only). It is provided only for backward compatibility, and you </P># h: e/ ^- D" z5 e
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
+ h, E0 t: p0 Z1 i<P>using this option. </P>: V5 D6 d2 s5 B8 K: N
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>
* G  J9 V, V- R' u) L+ i5 \$ L4 a<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>3 V# f4 q/ s7 `' m! W! @5 s: ]
<P>option, which is provided only for backward compatibility. </P>
6 P3 _1 W* X% S3 g6 Q; e, @<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>
/ O9 O" ?6 C. G) @5 s% _& j0 M  g7 J<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>
2 N0 n: L5 z5 \% @) u<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>* N) W# _5 L6 f: p
<P>not opening a Recordset based on a parameter query. For more information, see </P>
2 i+ p4 ]5 P/ ^( w" |/ s<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>
( Y1 g( r7 {6 t  C. j7 S( G5 F<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>1 M( }. b% K4 D
<P>snapshot-type Recordset objects only). </P>
( x  `; z5 h0 l% N& C: m0 ]% q<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>" W0 {3 r- g5 m& j/ }' T
<P>snapshot-type Recordset objects only). </P>" g9 h) m$ L2 |
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>+ w+ ]  H$ g3 C( s3 R# o
<P>and using both causes an error. Supplying a lockedits argument when options </P>
9 U0 n3 C9 O* z! ^, }# u<P>uses the dbReadOnly constant also causes an error. </P>% I" `& K% s) M
<P>  </P>
$ P0 h! o2 l+ j, W. ~5 w<P>You can use the following constants for the lockedits argument. </P>
8 d6 D' I1 O0 o+ ~# W- H% K) W2 i<P>  </P>
9 |6 S: p9 f0 j6 ]/ N5 F' \. z<P>Constant        Description </P>, _* T& E3 t0 h( z. S* t
<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>6 t" e6 `7 ?2 E; w
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>
* S4 L: m( B/ e1 T# M1 z& G<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>+ ^. a( W: o4 z
<P>run-time error occurs. </P>
0 K* u- L  x$ t7 `! _<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>: _% \9 {& k  R# q5 j/ P# j) X
<P>the Recordset in a multiuser environment. The page containing the record </P>
! Q* G  S7 m! j; Y0 _<P>you're editing is locked as soon as you use the Edit method (default for </P>
1 {. s( t  _- k5 _. K<P>Microsoft Jet workspaces). </P>
) n$ s7 D) n/ _3 G4 @<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>' w0 a" _3 c' ?! }& ^( j1 l4 C
<P>Recordset in a multiuser environment. The page containing the record is not </P>7 ~  a" q( o2 o. j
<P>locked until the Update method is executed. </P>
7 Y! h6 s/ @) W0 o<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>
; f: p5 d) H  J* r0 U& L( ^' k<P>workspaces only). </P>* @2 |& j7 _$ X
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>6 t9 A1 P; Q+ n, {; H
<P>only). </P>7 U, Z' }$ k# l8 g' i
<P>Remarks </P>
) G" d" ~; d& p2 `% i& p0 K" i+ w) @<P>  </P>1 G. R& }4 ?# m0 ~2 |6 P# n
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>7 F/ Q: r. e' ?9 A
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>7 A5 j" Z& m' R& E; V
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>% L# [$ R. \" d7 M
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>
8 B- E1 D4 I, a/ ]8 T<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>% u) _: G; a$ Q2 B. @0 K) R
<P>data source, you must first set the Connect property of the linked table's </P>9 p8 R  P* W% J' a) x/ `
<P>database to a valid ODBC connection string. If you only need to make a single </P>
! i, T* d9 c  A<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>
. }) I6 {, p# j5 D<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>
7 Z0 t0 f* \9 |<P>argument. </P>
1 x8 |( Y, H5 B; K( j<P>  </P>1 r7 `# a+ N4 {  D5 z9 M! |3 u- |
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>3 O7 x2 a( c. y# c- ^
<P>is of the same type object. If object </P># Z6 l& B- U" U" i
<P> refers to a table-type Recordset object, the type of the new object is a </P>
4 j: ^$ z% k# }" ?, X) X# D<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>
, m) t$ z/ o+ b% }- _<P>杢ype or ODBCDirect Recordset objects. </P>
* S0 D* C8 J! M) a( m<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>  p9 A# ]2 l6 ^
<P>select query in the source argument, such as </P>* q" e' l0 b! L' e. T9 V
<P>  </P>
, F3 u$ |% _# b<P>"SELECT LastName, FirstName FROM Authors </P>
' z# p7 x! P& d' r3 g  d<P>WHERE LastName = 'Smith'; </P>1 W8 a/ ]$ r9 M( i# \
<P>SELECT Title, ISBN FROM Titles </P>
* G" d1 S* f" S2 N1 c<P>WHERE ISBN Like '1-55615-*'" </P>
$ y/ ~2 f, n7 W# X6 V8 n<P>  </P>9 D  o% o+ ~, O5 ?% f' j( M2 }
<P>The returned Recordset will open with the results of the first query. To </P>
% ]& `1 i8 s7 c; @" d3 g, T<P>obtain the result sets of records from subsequent queries, use the </P>
( }7 N& c7 ]' X7 w<P>NextRecordset method. </P>
& ]% x& a) p- {0 x<P>  </P>, ]1 @$ V& D, y" K; _
<P>Note   You can send DAO queries to a variety of different database servers </P>
- t. [5 @9 v% I<P>with ODBCDirect, and different servers will recognize slightly different </P>
0 H2 ~& i. n  @/ u  @<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>
/ z" h* ?5 k6 d5 x<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>
- w; R2 G9 O" k- i<P>included through the Help menu. Be sure to check the appropriate reference </P># n3 ?3 ~0 N1 P
<P>documentation for the SQL dialect of your database server when using either </P>3 g9 \+ [3 C# k; ~2 Z+ [$ D
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>  k5 T0 L' i' k
<P>client/server applications. </P>) j. g' g% v- Q& S* d' r9 z' G1 o7 }
<P>  </P>
3 w/ V. h9 V  \  {* h<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>( S2 ~0 k/ X. h! m
<P>trap changes while two or more users are editing or deleting the same record. </P>
9 \' u0 E5 A; ^8 G<P>For example, if two users start editing the same record, the first user to </P>
6 [3 M9 K% B" G. R" q2 w0 f* `' e<P>execute the Update method succeeds. When the second user invokes the Update </P>
: g! ?2 f6 p( _: X6 @6 x9 V<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>  ^0 E* i% J. i+ f
<P>the Delete method to delete the record, and the first user has already </P>
; k  E  N1 A: H4 o3 D6 L<P>changed it, a run-time error occurs. </P>
: ~5 ^5 b, d. w# J/ Q<P>  </P>
1 g3 f. }' x9 i<P>Typically, if the user gets this error while updating a record, your code </P>
$ F, x, e' {( s; `1 P5 n' U; d<P>should refresh the contents of the fields and retrieve the newly modified </P>) ]6 D9 r9 o1 M6 o$ A
<P>values. If the error occurs while deleting a record, your code could display </P>! S8 N9 J# V9 V4 `" X" p
<P>the new record data to the user and a message indicating that the data has </P>
. @, H' L8 f# t$ e' k( w<P>recently changed. At this point, your code can request a confirmation that </P>
+ m9 t8 P4 R! E6 l<P>the user still wants to delete the record. </P>
- G6 \5 {; C; ^. y7 ^<P>  </P>9 B2 d- c: J3 d  N1 Z3 }
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>
( U# a( `4 [/ [. `<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>
& O% \2 w$ V& V1 k/ {: Y<P>later) table that has an IDENTITY column, otherwise an error may result. </P>
5 f, H5 E2 t3 _3 [; D<P>  </P>
2 D4 D. v8 E: T( H. `, p6 h, g; l<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>
2 u7 Y8 l: [4 w  M' x<P>the dbRunAsync constant in the options argument. This allows your application </P>' B/ c  s; ~7 j, J# ^. N" S
<P>to continue processing other statements while the query runs in the </P>5 x$ R  Q1 ]  ?: h$ ~
<P>background. But, you cannot access the Recordset data until the query has </P>- P$ Q' R. [/ A' Y& \  n, {
<P>completed. To determine whether the query has finished executing, check the </P>. n0 S/ T. @2 Z! d! R$ @
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>- V4 n, M+ V. _( r( u, O7 d
<P>complete than you anticipated, you can terminate execution of the query with </P>+ l2 [/ L; z( m  K, M$ V
<P>the Cancel method. </P>
# `. {- u" _  _9 U& E<P>  </P>3 R6 |* Z2 `2 P/ v
<P>Opening more than one Recordset on an ODBC data source may fail because the </P>' P1 t3 [1 l  K  W1 K. Q4 z
<P>connection is busy with a prior </P>8 A. P/ a- U3 @& x5 M% A# J
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>
, Q. _3 n- }+ N* J. O<P>ODBCDirect, if the server supports this. Another solution is to fully </P>
) x( y3 {; Y  G2 ?3 @6 w  j* ~<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>' t2 M" b# [# w: |, m1 M
<P>is opened. </P>7 R; q) S9 ?' H
<P>  </P>
% ]( D3 Q8 K! J7 c- j) A# F<P>If you open a Connection object with DefaultCursorDriver set to </P>, Q) R/ P% p% `- [; M5 U% A* A
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>
9 ]* F, L) W# l<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>5 k  C9 O0 l' ]
<P>h in the lockedits argument to enable update caching. See the Update method </P>
; N+ ~4 m. L1 p4 r$ o<P>topic for details about how to write changes to disk immediately, or to cache </P>
- o* H) R% y" |0 Z  Z<P>changes and write them to disk as a batch. </P>
! M& n, J' ?% g% I% C- O<P>  </P>+ j/ z& N3 O' q0 W( E7 y
<P>Closing a Recordset with the Close method automatically deletes it from the </P>9 R. Y' c4 @6 v3 a6 V

. e9 j9 L2 M3 H* C5 I<P>Recordsets collection. </P>& W  t3 j8 j9 Z! @
<P>  </P>
) h6 k8 R+ h, @+ n( {<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
, M: {6 q0 z6 }<P>with a non-integer value, and the system parameters specify a non-U.S. </P>0 @: o/ _4 g0 H, D  ~
<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>
& K2 D1 u) H( r9 z5 b3 c<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>
3 X. g# |1 Q  b* k, j0 H, o<P>Recordset. This is because during concatenation, the number will be converted </P>$ V; {1 i0 q. ?$ |) h1 |- y
<P>to a string using your system's default decimal character, and SQL only </P>3 T& v+ H, W  }
<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, 2025-9-17 22:21 , Processed in 0.362793 second(s), 53 queries .

回顶部