QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>
$ ~$ O- y+ I, U. [<>Creates a new Recordset object and appends it to the Recordsets collection. </P>  v, E1 h1 O6 k7 Q* d8 m' d. K
<>  </P>
/ W0 C) o, Q) N1 |- q<>Syntax </P>& ]$ X1 u9 K6 q" ~, r4 k$ Z) ^5 |
<>  </P>" k8 a& C0 _+ C) n
<>For Connection and Database objects: </P>! @0 Y2 I0 K/ _: j" i/ [
<>  </P>- A( s* y( E" H& C
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>
* `! W2 c5 l2 p; `( w9 j<>  </P>
3 i8 ]/ e( e9 ?# F+ }5 U<>For QueryDef, Recordset, and TableDef objects: </P>
! {. j6 O8 t& j/ ?<>  </P>
( G! t$ E: v0 L9 c6 d/ K<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>
8 D- T/ |2 p' y9 X9 L<>  </P>
, Y. ~! J( N1 U3 `: n<>The OpenRecordset method syntax has these parts. </P>8 Z1 k' C: y$ v" }* w2 S6 c
<>  </P>
- v' C+ j* y9 X7 w<>art    Description </P>& d  q  w% W: L. @1 D* j
<>recordset       An object variable that represents the Recordset object you wantt to </P>
+ h) \* K- _7 V; F<>open. </P>+ A! t+ i- r2 P5 M: T3 R! F" R  j
<>object  An object variable that represents an existing object from which you </P>, f4 k- P% r* \- x9 B! E
<>want to create the new Recordset. </P>) g: E6 V  |. j& u# f# W9 b2 K
<>source  A String specifying the source of the records for the new Recordset. </P>" L, T5 y+ u5 a* V2 M+ j3 a  t
<>The source can be a table name, a query name, or an SQL statement that </P>& ^& r( E# S  c
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>* K. H) ]& F8 h; G6 q
<>the source can only be a table name. </P>
7 x0 S/ m9 J5 N0 x7 T. [0 N<>type    Optional. A constant that indicates the type of Recordset to open, as </P>
6 t$ q3 v% n. T<>specified in Settings. </P>1 F; y6 e8 L* M8 z* {# t- H# L
<>options Optional. A combination of constants that specify characteristics of </P>
4 ]! N, E6 ?0 b* `1 o$ V<>the new Recordset, as listed in Settings. </P>
. x9 O0 r/ {" w- f9 r- Y<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>
8 A$ A' [5 p. N+ }2 d<P>as specified in Settings. </P>
) W' K! ]+ t5 K* w+ l6 j7 \<P>Settings </P>
+ n& o5 J% U$ Q) q: ^3 ]<P>  </P>
1 b$ ~% \5 e! D9 }6 n6 x/ L<P>You can use one of the following constants for the type argument. </P>; h0 C' \3 K$ b6 B$ v0 g4 R* P
<P>  </P>$ P  X+ A% {7 f7 X5 N% c
<P>Constant        Description </P>0 v3 f8 V, ~: F- ^$ L- c1 T
<P>  </P>8 c8 o- I* P- W1 i0 m- g' T
<P>  </P>
/ ^% q2 `# p1 a8 y6 B' }<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>
2 A- c$ l  e/ M- J<P>only). </P>
, v, }: [( F: w% G+ U( C: e: E$ @<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>
9 H* a' T; C* K; a) U<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>/ l$ R3 m5 f! ^5 d2 @3 I
<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>) B5 @( c0 s- ?# ]4 w, _
<P>ODBC keyset cursor. </P>
" T; v4 F+ a3 P) Y* X7 g% }<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>
( t5 H+ D( P- M% ^$ e<P>ODBC static cursor. </P>8 O7 F+ ]5 x$ `
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>
5 \/ C7 D# [" w  b; l% O' D<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>
, N2 {' O+ G2 k. h% a3 `# ]<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>
5 b" T) }8 Q2 M<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>
" z' A! C  j( a  j! S( b<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>. u+ x. L6 U: ^0 D: v( }5 k
<P>y. </P># ]- S6 a4 K( c0 {
<P>  </P>5 {' ^6 V- A9 R
<P>You can use a combination of the following constants for the options </P>
; F3 A1 R& a8 N# ~7 h<P>argument. </P>, F( }, x4 Y* x- n
<P>  </P>2 `. ]# h9 y  p
<P>Constant        Description </P>, F4 H' a4 m" j- l5 M% x" m8 Q
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>- i9 q. [, V0 V' ]+ X+ T3 ]1 h$ A
<P>prevents them from editing or deleting existing records (Microsoft Jet </P>
; S' Q* j" h  @6 j* u# t! F<P>dynaset-type Recordset only). </P>
! h! Y( f7 u3 c<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>
3 I- ?+ J2 v; h/ p! i+ P2 R<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>; w3 R- g8 x" n' ]9 @8 B! |
<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>
8 J. m. G0 |5 ~/ O4 }4 s$ j<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>, E4 h  N) H4 L" f  l
<P>useful in applications where multiple users have simultaneous read/write </P>9 o) \* f% I% j4 J$ [4 F
<P>access to the same data. </P>& U' L4 |1 Q8 m/ V! D- m
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>/ a" _" Z  h5 D3 T' m3 ^- s: b
<P>Jet Recordset objects only). </P># L3 R1 x/ U& N
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>
  y, T: N- ?8 L0 g. j- P* y<P>table-type Recordset only). </P>; ^$ X$ S& m/ T- G* s
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>
( h8 u  s) y" m<P>Recordset only). It is provided only for backward compatibility, and you </P>: C" v; e$ `1 n, {, {8 c8 A# r
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
6 v1 t2 ~( S" \<P>using this option. </P>
1 R  u. f+ y% i9 [- D<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>
/ Y$ A/ i% o% f& v! H<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>
( b% `6 s$ S% G' X; g<P>option, which is provided only for backward compatibility. </P>
5 E9 l: o+ {0 k<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>
# G* C; R* H2 g9 X' L' y5 t0 I5 B<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>: T6 b- q* O- q9 d9 ?
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>
+ ^& i3 p- ?4 V' g+ j<P>not opening a Recordset based on a parameter query. For more information, see </P>) i/ I; Q4 W* C; K  D
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>$ T$ K* w, G) K8 |+ P
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>+ |4 Q" ?3 J+ }5 ~  S) i
<P>snapshot-type Recordset objects only). </P>4 y2 P3 a8 p$ c2 z7 d* A
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>" ?9 V; g7 B8 F: _, P5 G# A
<P>snapshot-type Recordset objects only). </P>
5 U6 d4 Q2 c& T5 k/ W, g  O1 v0 S/ P  y<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>4 [( [8 @- O1 t( l% C
<P>and using both causes an error. Supplying a lockedits argument when options </P>  y8 S6 X2 _1 \1 |
<P>uses the dbReadOnly constant also causes an error. </P>. z: j/ k  w; r8 Y  j& T
<P>  </P>
9 Z  E2 j' q3 W<P>You can use the following constants for the lockedits argument. </P>
: D4 ^% l; W% ?<P>  </P>( z# p) d9 O# p- B5 a; q4 ]. [
<P>Constant        Description </P>
; J! ^6 m* I) l! N( \( W0 x<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>
, `) G4 m. T% M1 U8 i& U<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>
% y! d& H6 T  D+ a9 o* u- Y( x<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>/ t- L: l3 h0 Q+ r* m3 R; |2 f
<P>run-time error occurs. </P>; n1 m* t% l2 H8 l3 j9 w  }
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>6 Q# R+ @2 r' `4 q1 L+ ~. P
<P>the Recordset in a multiuser environment. The page containing the record </P>* A7 x& f! ?* U) V! u" ~8 p
<P>you're editing is locked as soon as you use the Edit method (default for </P>8 I* p9 v7 G5 t2 Z. m7 H; S
<P>Microsoft Jet workspaces). </P>
( ~( s* ?- z" j) h3 E3 T<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>) n/ }6 u2 n" w1 G! g4 K
<P>Recordset in a multiuser environment. The page containing the record is not </P>
; b$ c; j" ?$ F7 n6 J* |4 B7 t: a<P>locked until the Update method is executed. </P>/ d5 s! u/ N' w6 ?% O1 Y3 Q+ y8 L
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P># c3 `% ?# q- P- e6 B6 v
<P>workspaces only). </P>
8 t" g+ d( O: n* t. D1 m<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>
# y* z7 c5 h- H0 G' V<P>only). </P>* @1 U4 L& V" }% c& D
<P>Remarks </P>
9 S3 \* J2 d5 Z0 O. E  N8 F<P>  </P># k* @$ [9 J; T) Q
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>) V$ [2 A$ Q9 G! l0 G
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>: h4 m  I3 @5 E% J8 W' m
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>
% e9 A$ O9 A$ O  C<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>: H( v7 x# B! E3 i: A/ X" o" X
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>
1 e; e/ P* e7 [8 j<P>data source, you must first set the Connect property of the linked table's </P>- \( `$ z2 M+ N1 |6 ^+ ?2 b
<P>database to a valid ODBC connection string. If you only need to make a single </P>2 ^% H) L, R2 o9 l. I/ [
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>+ V/ |) z  P  \/ r
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>
5 m+ O* Z- h2 Z- R+ R' J3 g<P>argument. </P>
5 C, v: L4 z) S; \  ]0 I$ U" f<P>  </P>  B! }$ s* o0 A8 A6 h4 E; k
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>
1 F  ]2 Y( ]+ h* D<P>is of the same type object. If object </P>7 L! v" T& X4 Q+ H- t" }, B
<P> refers to a table-type Recordset object, the type of the new object is a </P>
8 N& Q. p8 P2 J5 n, Y8 v<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>
- W, X5 Y; ^- R- H! h) ]<P>杢ype or ODBCDirect Recordset objects. </P>
, P( a# e6 `$ Y1 F7 N! T<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>/ J) x. r) o9 g- g$ c
<P>select query in the source argument, such as </P>
* ~: n: p2 ]4 q! ^  m; S<P>  </P>% f. m$ e7 Z8 H/ V. k$ b  s% d
<P>"SELECT LastName, FirstName FROM Authors </P>
( w' t3 @% f! ~9 b4 z; B# o  S: u<P>WHERE LastName = 'Smith'; </P>
, I' B7 L9 k8 \6 i<P>SELECT Title, ISBN FROM Titles </P>
3 D- w3 b& Q$ ^# k& U( {. m* Q<P>WHERE ISBN Like '1-55615-*'" </P>8 u' }8 `! w- r! g  V
<P>  </P>
. {5 B' G: W8 i' b7 {6 X<P>The returned Recordset will open with the results of the first query. To </P>
- x, X0 [4 X; g, y8 ]: g<P>obtain the result sets of records from subsequent queries, use the </P>7 X$ N3 i4 K' C9 @, ]8 O" s0 m
<P>NextRecordset method. </P>$ j3 k  I6 f4 Q- P1 P+ G9 ~
<P>  </P>
3 V& P5 {! z6 A9 a( o; z& t<P>Note   You can send DAO queries to a variety of different database servers </P>
/ T3 G/ L% i4 s% U& n<P>with ODBCDirect, and different servers will recognize slightly different </P>
, N# A9 l, l2 G4 G7 O" _; I<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>
3 P7 c! V+ v# v. X* @<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>7 W; Y5 L$ J# x7 o) b) f* Z. R2 {
<P>included through the Help menu. Be sure to check the appropriate reference </P>/ m  F' B7 b$ Y0 y3 t( s8 W( B
<P>documentation for the SQL dialect of your database server when using either </P>* n5 i3 t2 z9 ^  ~/ H
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>* k, k3 ]- C3 C' X$ {
<P>client/server applications. </P>
; Z$ e" ]/ k8 Y<P>  </P>
; a0 b& y$ Z# ~9 o<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>8 f2 G6 M/ J/ H3 o$ N* S0 b
<P>trap changes while two or more users are editing or deleting the same record. </P>
: }; z3 L7 Q) T" D( w! r: E<P>For example, if two users start editing the same record, the first user to </P>
0 r/ L' T$ I" X8 v6 A<P>execute the Update method succeeds. When the second user invokes the Update </P>
& [+ U9 c) w6 W/ }+ q' E4 j; \" D, i, K<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>
6 y/ t. Z  G" j+ y! m( U<P>the Delete method to delete the record, and the first user has already </P>
3 X# j4 }; ~1 i! P<P>changed it, a run-time error occurs. </P>
9 F) Q; t7 \4 {( E<P>  </P>3 I: l" t- @- n9 J; L# Z, q2 Q& s
<P>Typically, if the user gets this error while updating a record, your code </P># K3 r$ W3 J% W) ]; Q/ g
<P>should refresh the contents of the fields and retrieve the newly modified </P>% W& `) n; u) m4 h5 R
<P>values. If the error occurs while deleting a record, your code could display </P>
* F# \4 f9 k5 X  q5 D<P>the new record data to the user and a message indicating that the data has </P>
# b0 q) y+ A9 \  U' ^( f<P>recently changed. At this point, your code can request a confirmation that </P>
5 I; |2 G$ ~, C<P>the user still wants to delete the record. </P>8 C" E% q) A5 m3 b0 O
<P>  </P>  A! H5 ^+ h6 V4 S4 U
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>% M) Z/ K3 H: i2 `$ U
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>) c: Q' Y8 O8 P, a
<P>later) table that has an IDENTITY column, otherwise an error may result. </P>6 e. K. |5 M( p6 h2 q: R
<P>  </P>/ B% S  }5 O+ B- k
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>, K3 Z/ U$ z1 j% m) Y
<P>the dbRunAsync constant in the options argument. This allows your application </P>0 A8 Y8 W, w- \( P% g7 Z6 ?
<P>to continue processing other statements while the query runs in the </P>
* j6 P) S7 `( S0 e- m( c" B<P>background. But, you cannot access the Recordset data until the query has </P>% j7 ^$ b1 O* L2 p& c' B8 J
<P>completed. To determine whether the query has finished executing, check the </P>" h1 x; l4 @6 b
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>
. ^5 b" w! Z7 i. Y' W9 h% ]; f<P>complete than you anticipated, you can terminate execution of the query with </P>
) T5 B6 m  k8 }3 v4 Y<P>the Cancel method. </P>
6 m* M  g% d7 {5 ^" h' u<P>  </P>
: ]$ }4 s- G. K* Q4 m7 p* B* I* W3 \<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
, D! s/ L2 g' [3 E" [& p) V: Y<P>connection is busy with a prior </P>+ K8 l5 I& `: _7 A
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>0 g8 c" I  F0 G" x* K
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>3 S  g  I3 p$ }& I) C# M1 x
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>
! H# g* m# f, `" }1 e% J, _7 T<P>is opened. </P>* U( @. e* h5 }. _; \1 k0 U
<P>  </P>- f, y1 j+ k7 H6 _4 b" ]
<P>If you open a Connection object with DefaultCursorDriver set to </P>
5 S; U; a' e( D<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>: E! {+ `) O9 i( `
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>
  z6 o+ S# n2 \0 T<P>h in the lockedits argument to enable update caching. See the Update method </P>
  s, b1 a* f: x" f  A! D2 G<P>topic for details about how to write changes to disk immediately, or to cache </P>. A9 B# h$ ?- w+ A
<P>changes and write them to disk as a batch. </P>
1 e! g1 }- c, @2 \# Y<P>  </P>7 X0 A3 L3 V6 t8 h# f( \6 R9 @
<P>Closing a Recordset with the Close method automatically deletes it from the </P>- m+ {7 _7 |7 d" m# m% B4 L9 D& ~; Q
- r+ a# L, s. r" t# e, C
<P>Recordsets collection. </P>
& W+ a4 d# l1 D' r<P>  </P>
$ H1 F( [% b5 J- Y" ~; H<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
4 [, t3 [" c9 _' ]! t1 i) b1 F& o<P>with a non-integer value, and the system parameters specify a non-U.S. </P>. E  b, o1 ]9 b; Q" ?
<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>2 m( f: E8 q% y/ S" f% S. R
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>
. s. O0 J2 P2 o6 E2 _<P>Recordset. This is because during concatenation, the number will be converted </P>$ P0 T' w3 h4 t& f
<P>to a string using your system's default decimal character, and SQL only </P>
7 c3 h# W$ Q3 E7 a<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-8-23 05:53 , Processed in 0.321892 second(s), 52 queries .

回顶部