QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |正序浏览
|招呼Ta 关注Ta
<>  </P>3 U( x1 g" L6 `  F
<>Creates a new Recordset object and appends it to the Recordsets collection. </P>$ q9 a1 f% J; |! ]8 n: k. J+ i  p
<>  </P>  m" l* F% q0 D& h3 |
<>Syntax </P>& E) J+ b9 y9 _: k
<>  </P>% X% |& Q3 q4 m4 ]* w/ r
<>For Connection and Database objects: </P>5 l  k6 w& Y$ s
<>  </P>: L, q7 E7 @5 X3 W* S  R9 i" P: _8 x
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>/ _; B  }+ t( U: i4 E; E$ R
<>  </P>
" Y" a8 E* g6 E6 W<>For QueryDef, Recordset, and TableDef objects: </P>
7 r5 r* b, S' }% [& A/ E+ ^<>  </P>
! [! ?; @( O2 i  j5 A& q7 W0 B, v8 I<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>% P7 J0 x9 H- |" C3 j$ N) s; h
<>  </P>6 \& z1 b4 @; j) F
<>The OpenRecordset method syntax has these parts. </P>
" w8 M, Z' I- R' |; c" g. m<>  </P>1 f; b: G& |# _9 T
<>art    Description </P>
- ~% e7 i* j. d<>recordset       An object variable that represents the Recordset object you wantt to </P>
; x2 k: p% ^3 A% N. V5 T/ |<>open. </P>9 V- |! B& t9 @& Z
<>object  An object variable that represents an existing object from which you </P>
; E) ^/ A! v2 Q6 m( P1 ~# T<>want to create the new Recordset. </P>/ q2 i- p" v/ l- h3 f+ M" r+ E
<>source  A String specifying the source of the records for the new Recordset. </P>  I  u" ^& y6 x) e) t7 W0 `- ^
<>The source can be a table name, a query name, or an SQL statement that </P>
; b7 \* Q$ |/ V9 [0 [<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>
3 m! {, }9 z  Y3 {<>the source can only be a table name. </P>
: J* U6 \% d  |3 a! G6 ~+ x<>type    Optional. A constant that indicates the type of Recordset to open, as </P>
4 n1 x% Q& W* a7 ?$ q# X  h- P<>specified in Settings. </P>* x7 t- M2 p* E' N  V9 N
<>options Optional. A combination of constants that specify characteristics of </P>! s0 D$ c4 o9 F! @) ^% v7 C
<>the new Recordset, as listed in Settings. </P>
$ r$ K, u; _  r. ]% J1 n, f<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>
" {5 ^9 i; x; w# K2 j5 D<P>as specified in Settings. </P>1 s2 O7 D/ A/ x& O4 \" T
<P>Settings </P>; e; `* U( ~( G9 T/ j
<P>  </P>
3 _* j* e: k6 I) \% l<P>You can use one of the following constants for the type argument. </P>" F* K* V- o- c' O8 z4 T- Z
<P>  </P>
. ^$ ]& s8 o( s! x! d<P>Constant        Description </P># R4 m, _6 P% E
<P>  </P>7 V; |7 J) |1 D/ S  C/ R
<P>  </P>
" _/ u2 m- y/ d<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>% v/ R' Q5 A" |) E& h( }
<P>only). </P>
& [1 x  H; M: F- V  {<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>; f3 \, }# g$ H! D
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>+ Z1 D0 e6 a2 v% p2 j
<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>8 \! C8 B/ C+ c/ i# S
<P>ODBC keyset cursor. </P>- _5 y: k; D9 p" g1 i( C3 ]
<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>
& y! U# ]9 G3 O/ P8 b7 S<P>ODBC static cursor. </P>
) c, R8 w- K9 n<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>1 k3 F7 n. e+ M& u$ Q; _
<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>+ N" D) K  N+ ?' W& u
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>3 G7 e& @8 p' e  M" T
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>7 f  Y, `9 N% J* @0 Y% k. H7 S% g8 [
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>" Y* J) r1 o% V- t* R. i0 X# o) T
<P>y. </P>5 b5 c" B$ S) R, W2 b8 x
<P>  </P>
7 L9 j( Y$ v! G% x" N# s<P>You can use a combination of the following constants for the options </P>
- ^) J: m( o& [( S8 u8 |( {$ a. X<P>argument. </P>$ }. y( u9 b' r: ^2 q- x0 U
<P>  </P>/ J3 g0 X# A; _$ \% N
<P>Constant        Description </P>) S' N8 O) R6 v( c4 I) b. t: f
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>0 m' A2 {9 d4 {
<P>prevents them from editing or deleting existing records (Microsoft Jet </P>
0 w& [% [4 a0 S6 T9 j/ X4 K<P>dynaset-type Recordset only). </P>
$ q' w$ v+ E) Y5 U; y) `<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>
4 \/ v0 H$ W  F/ `- O<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>! }) j" w3 o5 A- F
<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>
! T" u$ L0 Q" Y1 z7 C<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>4 T9 E& Q; d+ m+ I: F) H6 K' S
<P>useful in applications where multiple users have simultaneous read/write </P>) s" Y1 E$ \$ ?2 `* _! h
<P>access to the same data. </P>
' F0 o* D: N, k5 ^" x<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>, v( e) Q4 c* g: q3 ~- t  |8 t8 C
<P>Jet Recordset objects only). </P>+ L6 ~1 S- B- P3 G
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>! _, l% Q0 l9 R2 H
<P>table-type Recordset only). </P>
- j. ~3 Y% U2 X1 G% J<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>& P- b1 ]' X/ T6 q/ w- H
<P>Recordset only). It is provided only for backward compatibility, and you </P>
2 i0 M0 P# z- N0 H' V/ t9 |& n+ ~<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>. I, J% @) p( o; ]
<P>using this option. </P>
/ b" s3 b: X9 M0 F  {. Y, _<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>
8 m4 I$ b; g* o- z* H) `* B<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>
$ K& h0 A0 |, Y% ^: }<P>option, which is provided only for backward compatibility. </P>
. g. ^: c* B0 Q- V  R/ t: U<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>5 i( g5 k" X- D: c3 h* k5 v
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>4 v' k4 M; p  G/ f( b0 N+ [! v: k9 `
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>
; T9 M0 V# y/ }$ j9 _7 P<P>not opening a Recordset based on a parameter query. For more information, see </P>  i4 c8 \4 j. d  l
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>
( b( t, g' q7 j9 a<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>
" M/ |3 B: C, K/ N, R<P>snapshot-type Recordset objects only). </P>! q% f$ J9 A# B9 T: w
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>" w" k/ E" y, s5 C* H' p' l7 w/ T
<P>snapshot-type Recordset objects only). </P>
7 Q& E, f3 R! e' z$ q  x4 x<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>) Q5 I: E; L) ^, |8 @
<P>and using both causes an error. Supplying a lockedits argument when options </P>
3 C2 j6 B) N3 [$ E: W- V<P>uses the dbReadOnly constant also causes an error. </P>
1 e  K( t6 `4 v2 L<P>  </P>  N7 y1 l6 K4 e* ?
<P>You can use the following constants for the lockedits argument. </P>! ]4 @: V" b' J; J0 E/ n, z7 f
<P>  </P>
! J( T; \( o# f, Y; V& t: z/ C<P>Constant        Description </P>+ N' z3 x) R+ E0 q6 [9 [( R
<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>
5 \4 U7 ?! `( I( ]5 m7 q<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>' {( N0 |6 q5 B2 i& l
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>3 V9 K# b9 X1 k# Z  ]5 |6 ]3 D) J% C
<P>run-time error occurs. </P>2 y1 }" O+ \( u3 M! p. A# q9 v
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>
7 U8 ~' \( U9 \1 R2 s<P>the Recordset in a multiuser environment. The page containing the record </P>
, m$ N. _5 ?% n) {+ ~* M: U# H+ x<P>you're editing is locked as soon as you use the Edit method (default for </P>' ^% X: J  I' T& D0 }4 r
<P>Microsoft Jet workspaces). </P>
. `! m. H3 U" ~* i% Q3 ^<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>( [5 Z' Z% ]& Y4 G  h+ M' {5 r% L! C
<P>Recordset in a multiuser environment. The page containing the record is not </P>+ P0 R9 v8 z; l2 Q; P3 r8 W
<P>locked until the Update method is executed. </P>
* ~9 e# H! K, A" o' o<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>8 S; B! y6 H' c
<P>workspaces only). </P># d( c( z/ q. M, e! _
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>; G* Q/ T* H% L$ ^
<P>only). </P>
0 D3 c, S) [3 K6 d8 O<P>Remarks </P>
- s+ r, h" Z5 l/ O<P>  </P>
% O" k, e& m2 C- F1 [3 \  o<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>
& E1 d' L, G7 [+ E<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>. x4 b# _4 X& u+ @6 j
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>( ]; _5 R! J4 j+ F  T
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>" q% s  Z6 F( e9 C' b( V1 g" L1 D
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>
8 Q9 Z7 a9 S) q) F" w6 n$ }; M6 S<P>data source, you must first set the Connect property of the linked table's </P>
! Q8 q; h" p( W: g: [# [<P>database to a valid ODBC connection string. If you only need to make a single </P>$ F7 U' Z% ~; f* p) v" d  k3 h
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>
, Z* b. i  A  Z3 M<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>( I$ z0 M: s' p1 t
<P>argument. </P>
% Z% G: B& R. u  }' I. t<P>  </P>
# G, s  o. m% X+ g! d9 h% z<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>& a* Y  S/ o) F' {* V
<P>is of the same type object. If object </P>! H: i6 E- }$ V" v! F' W& u5 M" T: Y
<P> refers to a table-type Recordset object, the type of the new object is a </P>
6 q' z% Y3 ?! I& H. m<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>9 b$ M9 i7 A  s6 y; q8 H: t, }
<P>杢ype or ODBCDirect Recordset objects. </P>% A4 H3 i7 m! R& m0 [. P# n+ |: D
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>
; R3 v( a2 n. X<P>select query in the source argument, such as </P>
) O5 D* Q6 g0 U9 U+ |6 H- c<P>  </P>6 ?( w6 D: K! ]4 e/ G# k9 O" r0 o
<P>"SELECT LastName, FirstName FROM Authors </P># i* k" V; l4 O; J$ y
<P>WHERE LastName = 'Smith'; </P>: ^5 g2 {6 W5 V: [0 z* [
<P>SELECT Title, ISBN FROM Titles </P>/ E+ f( S/ y. z' Z0 q# \# a
<P>WHERE ISBN Like '1-55615-*'" </P>; W9 E/ P- F* ]5 I" A
<P>  </P>! V5 q9 `8 `, g) n  ]
<P>The returned Recordset will open with the results of the first query. To </P>
  n; E- K9 L0 x, U- w0 ]# h) b  s; w<P>obtain the result sets of records from subsequent queries, use the </P>1 s: ~) v/ \! R
<P>NextRecordset method. </P>  N4 z. D1 \( P1 B! g$ k! i1 Z
<P>  </P>. D3 `5 \% u2 j; m
<P>Note   You can send DAO queries to a variety of different database servers </P>
; y+ ?2 Q0 \$ v( O: f4 }<P>with ODBCDirect, and different servers will recognize slightly different </P>
* y$ u, H/ u) d' @- h# O<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>
6 }, p( H! w) N' V# o<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>  x7 _; {; K* e, u. ~5 C8 ]
<P>included through the Help menu. Be sure to check the appropriate reference </P>
! l: v& z4 b3 V( b* f. k9 D+ v<P>documentation for the SQL dialect of your database server when using either </P>* r* U9 P& A) h* G; w) T3 R2 l# B
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>5 X$ @4 I* e% ]" M
<P>client/server applications. </P>1 _+ ]& }) x7 F6 V/ i+ r
<P>  </P>( Q6 [- S% q' i, ?1 h- ~
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>3 a1 s& C9 X9 C! [
<P>trap changes while two or more users are editing or deleting the same record. </P>
2 r0 W1 \/ C; l& g. o! r8 `<P>For example, if two users start editing the same record, the first user to </P>6 k9 i; ~8 M8 q8 d, Y2 _
<P>execute the Update method succeeds. When the second user invokes the Update </P>
+ A1 h1 x, {) I1 F4 c# v<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>* X% Q- O( b1 M, w  V
<P>the Delete method to delete the record, and the first user has already </P>
4 v' G. L$ k/ t  \( d1 p<P>changed it, a run-time error occurs. </P>0 y7 y" }4 V; |4 d8 p/ r
<P>  </P>
5 R, M6 n" R6 s<P>Typically, if the user gets this error while updating a record, your code </P>
( b5 F1 P8 R0 A' Y3 _<P>should refresh the contents of the fields and retrieve the newly modified </P>' V1 x. n2 \' V6 ?
<P>values. If the error occurs while deleting a record, your code could display </P>! X* [0 `3 V0 \1 G9 E% F% s
<P>the new record data to the user and a message indicating that the data has </P>
+ `( K* A! h( N0 s6 \<P>recently changed. At this point, your code can request a confirmation that </P>
- R4 t5 |  I7 Q" `1 z/ B<P>the user still wants to delete the record. </P>7 _# `% z0 g& i$ }
<P>  </P>6 c/ P% Y/ {; w, Q' G7 i( \/ h# ^
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>
6 k' m4 C& u$ }<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>3 k& k/ h6 Z5 I  s; R7 T
<P>later) table that has an IDENTITY column, otherwise an error may result. </P>9 L0 X$ c# ~! G+ y( w" e+ F
<P>  </P>
. L4 \, h3 z) \6 S, w' z2 b; J<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>
0 F, ^8 b5 H9 @  v7 v$ F<P>the dbRunAsync constant in the options argument. This allows your application </P>  y: M! x+ E; Z+ W
<P>to continue processing other statements while the query runs in the </P>1 I  ^6 x6 G0 Y, A1 G
<P>background. But, you cannot access the Recordset data until the query has </P>
; c) E  y& k- v9 y<P>completed. To determine whether the query has finished executing, check the </P>
4 c8 |- R% J7 t' h<P>StillExecuting property of the new Recordset. If the query takes longer to </P>3 v- `: \/ F* p2 C; x0 \( ^! o* Y2 ~
<P>complete than you anticipated, you can terminate execution of the query with </P>/ C* b9 X2 n9 m+ `! f4 v
<P>the Cancel method. </P>( w, B/ C) o1 ~
<P>  </P>9 V$ k' `8 i4 r( G* d9 G$ a
<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
6 ?; D& J" y3 z4 A: W; c<P>connection is busy with a prior </P>' T. }" Q. l5 u9 G
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>
# o( m% F7 X: W) L<P>ODBCDirect, if the server supports this. Another solution is to fully </P>
, C0 ^5 m. J, t. k5 j) d<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>
* r; a* z% v# i/ H  H- L/ a# j$ A<P>is opened. </P>1 P' f" ]/ f2 l4 }4 e
<P>  </P>
$ M9 N8 u$ L4 G( N: E! h# q4 V. [<P>If you open a Connection object with DefaultCursorDriver set to </P>2 P# r+ `2 c: G4 t. N9 C* I6 w
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>" q+ T9 w' s$ W7 L1 c
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>
$ F5 l9 Z, D9 y5 b1 R<P>h in the lockedits argument to enable update caching. See the Update method </P>: X- }1 m' ?9 R( \* l
<P>topic for details about how to write changes to disk immediately, or to cache </P>; G, V7 w0 k8 f- M. n
<P>changes and write them to disk as a batch. </P>8 p/ \' O6 j* v8 @
<P>  </P>( y3 x! t$ e/ |& y+ v* }1 \$ `: n
<P>Closing a Recordset with the Close method automatically deletes it from the </P>
1 ~5 |- ^, C1 e% a! h/ c7 o( u3 \
<P>Recordsets collection. </P>
) L- ~6 J" U5 `+ t/ i, g, Y<P>  </P>
6 b: |  s; B. y3 R3 l: U<P>Note   If source refers to an SQL statement composed of a string concatenated </P>( ~' |( @7 q- A
<P>with a non-integer value, and the system parameters specify a non-U.S. </P>
2 X  G4 U/ f' p4 j<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>
% ^# q- Z& l: o" l! k<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>
& s, t) p* s  q8 |( p<P>Recordset. This is because during concatenation, the number will be converted </P>
  e, `$ X! P1 v<P>to a string using your system's default decimal character, and SQL only </P>
7 W2 L+ e1 Z. `7 q<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-4-12 05:55 , Processed in 0.446183 second(s), 52 queries .

回顶部