QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>
4 L8 T2 g" k3 b* t' }* V<>Creates a new Recordset object and appends it to the Recordsets collection. </P>7 Q- F6 O% ]9 Z) C: f
<>  </P>0 \, y  e+ T9 ~1 w1 W  _
<>Syntax </P>1 A) U/ {8 O% \# ]( p/ ]
<>  </P>1 b# t! M& I4 e% V, y
<>For Connection and Database objects: </P>* D* C7 c; O5 u: i$ ~8 w  E
<>  </P>5 [& c, f1 y/ ~3 q3 v$ R9 [. {
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>2 g3 q" |0 I2 Z: E! v1 p, C
<>  </P>
+ T9 w; a# [+ ]/ Y! {8 o6 c<>For QueryDef, Recordset, and TableDef objects: </P>3 P! ]7 g* m6 b8 t
<>  </P>) j8 q4 v+ k" T
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>
4 c1 d! G2 f( c9 `5 x3 L+ G<>  </P>
* }( s$ E2 e; y<>The OpenRecordset method syntax has these parts. </P>1 b3 g1 {2 \# w- p! P: B2 G( K
<>  </P>
2 T1 h! W+ h1 g+ j<>art    Description </P>, U" ?+ b: i) P
<>recordset       An object variable that represents the Recordset object you wantt to </P>  F0 [5 f0 y6 f8 T/ g. l# q! Y# x
<>open. </P>
7 T; |1 e9 y4 P3 t% ^% c<>object  An object variable that represents an existing object from which you </P>2 F2 j. v% _$ P
<>want to create the new Recordset. </P>8 D0 A; A, v3 M1 i
<>source  A String specifying the source of the records for the new Recordset. </P>
% y! T1 Z1 k/ f, V8 A<>The source can be a table name, a query name, or an SQL statement that </P>4 ?' ~- B$ B  f0 Q0 T0 A/ u% h
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>
# u: n2 S5 {% R3 E, J: q7 L<>the source can only be a table name. </P>
; ~1 y9 m/ a! f$ d<>type    Optional. A constant that indicates the type of Recordset to open, as </P>7 H+ R8 }3 G1 n2 [' Z& d* x  i
<>specified in Settings. </P>& A( ?# H3 B% C
<>options Optional. A combination of constants that specify characteristics of </P>. H# \# v* t9 C; `" W, ^+ D
<>the new Recordset, as listed in Settings. </P>6 z; P2 c1 q" Z) c- T) w
<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>; F* A' h) i- L7 E# Q; _0 n
<P>as specified in Settings. </P>
1 h# e  O- g: O6 o" X1 C<P>Settings </P>
  }9 N+ s4 t% U+ X/ G<P>  </P>" y2 F2 c2 v/ k" a2 C  f* ?4 n
<P>You can use one of the following constants for the type argument. </P>
2 a8 B5 {; I3 i# w& Q<P>  </P>6 z9 b. w8 _: r: V% ~% }
<P>Constant        Description </P>
0 N* P2 Z9 L) `( {<P>  </P>
1 i5 z6 u$ h& I% G$ ~4 g<P>  </P>4 A: O6 c7 z5 t; n8 ~) d5 ]; \
<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>
: T( ]0 |! ]4 u) M3 E6 z! V<P>only). </P>' C; M1 D; s0 D) }+ A# t0 o: A
<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>: O  \" \4 A6 }- u5 e1 O
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>
6 Z) X0 v- m) b: ~<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>" ^6 t8 g" }/ @6 |* @* _8 \, [
<P>ODBC keyset cursor. </P>
; d* P% {4 x  s<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>
7 A5 M3 L4 `( n& s5 o* B% R<P>ODBC static cursor. </P>
/ }% T( a4 Q3 E$ u7 Q  y7 e<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>
5 R! K4 C: x' s) w2 u<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>  W/ j. h, K) _5 e3 d' ?
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>7 q2 n. V4 I0 a( C, V
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>
4 Z8 Z' S( F. R7 ]6 |+ M<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>( Z: v% U$ O! \& i( ^% s: c
<P>y. </P>; W- t8 a. j- j# O4 m
<P>  </P>6 W- _9 \5 R2 F
<P>You can use a combination of the following constants for the options </P>
! A& k$ b. \; X4 ^<P>argument. </P>
  F) v1 `9 X9 p4 V( T, T- o<P>  </P>- j/ T) M' @6 M
<P>Constant        Description </P>
+ f8 n( K, P& G/ `1 t/ D  \+ W<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>2 t: f1 d4 H2 L( E6 n
<P>prevents them from editing or deleting existing records (Microsoft Jet </P>; U% z7 J. ?; C7 l! V9 ]- g* k
<P>dynaset-type Recordset only). </P>
9 R+ R9 W( D' S# s+ p<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>
$ _; E. O& P/ y" x7 ^<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>" |+ S0 g0 W4 G
<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>* |+ I7 N( V; u! g2 H1 |7 |
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>
% q. `7 F3 {4 y  z/ X, n<P>useful in applications where multiple users have simultaneous read/write </P>
/ W4 t4 P8 c$ w, j; B<P>access to the same data. </P>
9 v! H* @! D$ k8 v6 R' l9 e+ W4 F" F<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>
. H; @9 _9 n" S) r% b<P>Jet Recordset objects only). </P>0 K- v$ e9 @  S# v$ v6 l1 H
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>/ w& K1 t$ V1 i7 _
<P>table-type Recordset only). </P>
2 ?- R; R* f! h2 L<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>
) m! I2 q1 }9 H4 e9 Z! o; \<P>Recordset only). It is provided only for backward compatibility, and you </P>! I) C7 P( m: w1 ]
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
$ \0 f' [( x9 N* }6 t$ `# `9 B<P>using this option. </P>
/ B6 V2 P/ ^# O# n<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>2 I2 ~& c7 \: t% |! D% r6 `
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>
" h! O- [) ?2 p/ p% l( H$ ^) G<P>option, which is provided only for backward compatibility. </P>
# ?" P1 H% d. D& K; Z<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>
. J5 ~# m) }5 ^& {" [7 v<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>
9 ^7 ?+ F! v7 M6 I) [3 j<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>
9 Y" I( n7 b* `+ F# Y8 ~<P>not opening a Recordset based on a parameter query. For more information, see </P>
8 r6 Q5 f/ Y8 {; |: d, [- a0 U; f<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>
! A8 j5 `$ r6 _<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>
) `) m7 Y5 z& }% s, z. u<P>snapshot-type Recordset objects only). </P>8 n8 A1 h& \2 \* H- g% e4 D7 o
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>
9 U+ X- B6 s' ~: p# J<P>snapshot-type Recordset objects only). </P>
$ B$ o8 r2 `: O* e1 ]/ j) P<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>
8 p' X: K7 p8 d* [<P>and using both causes an error. Supplying a lockedits argument when options </P>1 \8 \8 C, ~3 j0 ]( l
<P>uses the dbReadOnly constant also causes an error. </P>
/ g3 @3 `) |* D: F<P>  </P>% ?5 R* ]: B8 k' z& ~
<P>You can use the following constants for the lockedits argument. </P>
& z5 t8 w8 k* A<P>  </P>
, F- W4 d% e& ?$ B% Q5 O9 X<P>Constant        Description </P>( |, K/ [& y$ T; H
<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>
- L6 E: y9 l2 N; E; s  e<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>, \! k! r! D4 y* {
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>
& u' X( g/ o9 @% U<P>run-time error occurs. </P>
2 K5 P, d* n8 ^/ Z6 R+ w; K<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>
3 e) y9 u- w* {$ P) ^<P>the Recordset in a multiuser environment. The page containing the record </P>
0 }, A# Y; Z9 B# `- W) S% G( h) |<P>you're editing is locked as soon as you use the Edit method (default for </P>/ J" L( b0 J- G" t
<P>Microsoft Jet workspaces). </P>7 Y# o7 p$ s0 \) n) I$ z9 Y7 t) q
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>! b. J* Y0 a/ e8 d
<P>Recordset in a multiuser environment. The page containing the record is not </P>6 m6 @8 T. y0 Z3 Z; Y6 k0 Y' p5 p6 j
<P>locked until the Update method is executed. </P>
( V4 w& h5 K  u2 P( ^<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>
2 F8 T' m3 ~  T  x<P>workspaces only). </P>$ s1 \; W0 h. i' B! I  J
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>
6 D$ b, d5 u8 _  D6 O' A2 B<P>only). </P>7 c( [! t( O, a7 |! j7 X9 Z) n
<P>Remarks </P>9 g5 `! n- a, [# q& x- O
<P>  </P>2 h4 ?/ V- w  Y4 S! B' }5 f
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>
5 ?' B( r3 q" [* h& t<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>
# d9 U! X" O2 g2 `- s3 H: R8 a$ H<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>5 b6 K0 |2 R* `* s  M# q
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>) U3 {1 {+ w) n8 P  c9 m
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>
0 s  C9 t. V8 c! G<P>data source, you must first set the Connect property of the linked table's </P>
& e& g0 R6 t, P& S<P>database to a valid ODBC connection string. If you only need to make a single </P>( [: y+ ?% t, j. Y
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>
1 T5 C5 Y8 l7 N- s<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>
2 j  K4 {* L* F/ x; x! Y7 b% k<P>argument. </P>0 d; t$ c0 i$ Z: ^! `. n: Z+ }& ?
<P>  </P>
' Q1 ^1 h" i9 F/ j. y( g5 n<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>* w1 _4 v; X5 ?
<P>is of the same type object. If object </P>. ?! A' t# D, ?8 f  m, H
<P> refers to a table-type Recordset object, the type of the new object is a </P>* O' p; G! K7 g7 K- z
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>
7 p8 O. |. U9 w4 l6 K  @<P>杢ype or ODBCDirect Recordset objects. </P>- V/ n! w5 y  p
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>
0 \* H% `- }& e* l' V% b  c<P>select query in the source argument, such as </P>
, {" k, _2 S( E" g- B- I& n<P>  </P>* @/ t. r7 m+ D  Y' T) `
<P>"SELECT LastName, FirstName FROM Authors </P>
( I* w; b& V& n% Y<P>WHERE LastName = 'Smith'; </P>, |8 V3 K9 b" {' g& V( l7 v% U0 L
<P>SELECT Title, ISBN FROM Titles </P>
* J! u1 _) O' ]/ ^<P>WHERE ISBN Like '1-55615-*'" </P>" w7 ?( O% K8 k
<P>  </P>
3 b; V& a' j1 V* }7 q<P>The returned Recordset will open with the results of the first query. To </P>
+ `1 |' _4 O7 Q1 b<P>obtain the result sets of records from subsequent queries, use the </P>
0 S2 k+ v/ w. X# ]<P>NextRecordset method. </P>
" W1 c5 ?5 b5 \7 W* r, m<P>  </P>- R' P$ ?# f) a; h; `# R
<P>Note   You can send DAO queries to a variety of different database servers </P>' c: X" D; o2 Z! o" D- U
<P>with ODBCDirect, and different servers will recognize slightly different </P>
( l2 g& l: j: ]( T- z& z<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>
, t& C, J# S: o) U- U( b- e<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>0 a5 b6 o- W* H6 Z/ s6 t+ o, {8 Q
<P>included through the Help menu. Be sure to check the appropriate reference </P>- n$ q) A" g9 Y" c1 c4 d" n
<P>documentation for the SQL dialect of your database server when using either </P>
; u& m! |% x" c' m<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>
4 m" x. ^# Z* P% o+ {<P>client/server applications. </P>
3 z+ a* i; e4 \, i4 e) k5 u4 i<P>  </P>
3 ^& o  C6 X6 P& [) M<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>: i' Z0 L2 |2 |6 N7 e5 a/ G$ Y
<P>trap changes while two or more users are editing or deleting the same record. </P>
, v9 ^8 D: w% g# n) s<P>For example, if two users start editing the same record, the first user to </P>
5 b% q! D5 m/ Y6 Z<P>execute the Update method succeeds. When the second user invokes the Update </P>& o+ D9 }$ ]; X2 `7 c+ C
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>
- x7 b2 W# o3 U1 \! r: J<P>the Delete method to delete the record, and the first user has already </P>  p% o6 P$ `2 c# \( `
<P>changed it, a run-time error occurs. </P>; o; r$ J- z2 Q( p
<P>  </P>
8 B# T% a' ^/ k& O<P>Typically, if the user gets this error while updating a record, your code </P>( D" O" G# n" q% b, @1 B, T/ E
<P>should refresh the contents of the fields and retrieve the newly modified </P>8 B- p, d6 b7 L" [' e* m+ [. I
<P>values. If the error occurs while deleting a record, your code could display </P>
$ m: e# q! C- P3 Z0 v5 W<P>the new record data to the user and a message indicating that the data has </P>: K& l6 D6 \" J/ x
<P>recently changed. At this point, your code can request a confirmation that </P>" z' H5 b* a1 H$ b4 s1 @& q
<P>the user still wants to delete the record. </P>
5 V' m: V1 n9 K' O, Y! o9 ^<P>  </P>7 z# x8 |' Z6 j2 a5 P
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>4 S; p+ t. g: ?( R
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>
7 y- @) S6 J0 k8 i$ |/ v<P>later) table that has an IDENTITY column, otherwise an error may result. </P>
2 t' y) w) `, H' ~<P>  </P>
$ C& }6 l9 z5 U/ J" O<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>1 o0 q; K! y# k5 U% B
<P>the dbRunAsync constant in the options argument. This allows your application </P>
# I& a" q+ j$ T$ W+ D0 A) b8 R; ^% H<P>to continue processing other statements while the query runs in the </P>
; j; R- z! E% r5 v9 D& E<P>background. But, you cannot access the Recordset data until the query has </P>- S- a  i* @" n3 R7 c' B) P1 B
<P>completed. To determine whether the query has finished executing, check the </P>; m' i8 Q) j+ D4 W0 }' j. }
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>0 E7 ]3 ]# h$ p- A
<P>complete than you anticipated, you can terminate execution of the query with </P>; Z2 }0 d3 m6 a6 h1 G- a
<P>the Cancel method. </P>
: d" B2 p& c! a" @5 A2 ]6 R<P>  </P>
7 V7 S8 }2 j; P0 c% J<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
3 E0 l' d- A. N! J  r<P>connection is busy with a prior </P>
/ u# t# t$ Q; d2 g<P>OpenRecordset call. One way around this is to use a server-side cursor and </P># v3 g+ N2 M! a# t5 l) B
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>
2 g+ W0 i' s0 S. {0 ?<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>
- P. S" x  v. ~* |( r<P>is opened. </P>9 c. B2 s7 g* z7 Y7 b2 ]  s
<P>  </P>4 [/ }1 e8 U3 {( P, Y
<P>If you open a Connection object with DefaultCursorDriver set to </P>- C& y3 H, F  r% J9 Z5 K
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>
0 @; `5 u3 C7 s3 V6 t' Y<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>
" S  s& x: `; S4 J<P>h in the lockedits argument to enable update caching. See the Update method </P>4 u2 v" l  u8 Z7 f; t3 q. v6 t
<P>topic for details about how to write changes to disk immediately, or to cache </P>! q& q2 ~! O  a) l: s9 T+ U
<P>changes and write them to disk as a batch. </P>
3 f' v5 w+ c$ W. ]2 k<P>  </P>- y+ H) f) j/ A! q+ K: U3 V. a
<P>Closing a Recordset with the Close method automatically deletes it from the </P>, ]# f- S. o/ K7 J* G

1 F) A0 f3 z& Y0 B9 a1 w<P>Recordsets collection. </P>6 a5 P! n9 ]& m& s. L& @' i
<P>  </P>; `5 ~5 j9 H1 F6 k: P% v8 f$ n
<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
1 a! \% \! V' A<P>with a non-integer value, and the system parameters specify a non-U.S. </P>
: R  P" o: n2 j<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>, k- p% g) l& M- }2 R) n" Q
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>7 f% o, V( f$ O2 N& h5 A2 @" D( @
<P>Recordset. This is because during concatenation, the number will be converted </P>
. ~3 Y* l4 \7 z! B) _, H0 I8 l<P>to a string using your system's default decimal character, and SQL only </P>
8 T2 \! p9 b, j$ a4 [* `7 u<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-8 09:31 , Processed in 1.278402 second(s), 52 queries .

回顶部