QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>
( \, X5 n1 z4 X9 J# s7 q9 R<>Creates a new Recordset object and appends it to the Recordsets collection. </P>2 _" x) Z( G4 m
<>  </P>
$ A/ \2 {. I; p% a5 i1 I& R, V<>Syntax </P>
" y' W* F) z8 B4 |& T<>  </P>! p1 r, e" X) o
<>For Connection and Database objects: </P>
. B8 b- @, z  c3 y( e<>  </P>
1 l1 D0 U9 ]; Y0 q4 _  T8 E" `3 b  t<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>/ O* a/ g3 B& R" \) b
<>  </P>0 E% f8 h7 A* F; Z
<>For QueryDef, Recordset, and TableDef objects: </P>5 W: |6 Z5 K$ F  ]
<>  </P>2 |, G3 W4 Y% @' \* G5 \6 m! ^
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>
: I9 a8 T( \6 M$ n- z<>  </P>- K6 _0 w8 U# i$ \, M9 F" C+ c1 o  ?
<>The OpenRecordset method syntax has these parts. </P>- s; L. @0 W/ ?; a2 e, |
<>  </P>4 ~# j# O& n/ w0 b3 Y) X1 u& U
<>art    Description </P>+ v8 S/ P3 a8 h+ M1 w9 w' ?% k
<>recordset       An object variable that represents the Recordset object you wantt to </P>8 O# M5 j0 l$ p/ e
<>open. </P>
  F& r, a/ H: w8 L" c# _<>object  An object variable that represents an existing object from which you </P>% w5 c$ L; l: e! y- `5 S' v
<>want to create the new Recordset. </P>& }# y3 [  ]* T+ X/ Y! c
<>source  A String specifying the source of the records for the new Recordset. </P>$ p  b3 s9 _+ g- e' B0 R% j. y
<>The source can be a table name, a query name, or an SQL statement that </P>
' O4 k& |+ A, |: x<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>
8 p1 o  d% c5 f% z4 W0 k' b<>the source can only be a table name. </P>
' W% @) m) t" c0 P3 _& X3 \<>type    Optional. A constant that indicates the type of Recordset to open, as </P>
& N* T1 A3 q: c8 [+ I. u5 m0 C<>specified in Settings. </P>
0 x8 E! o$ }  C7 O<>options Optional. A combination of constants that specify characteristics of </P>
$ }! I' v; u5 k; p6 f% p1 M7 u<>the new Recordset, as listed in Settings. </P>
' D8 N4 Z$ {6 `2 s- |2 p<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>
! |3 _) @! M1 J% i5 L<P>as specified in Settings. </P>, p0 J3 Q$ Z/ C* a+ g' A0 |9 y
<P>Settings </P>
5 C  b  `3 X# d5 Z# c<P>  </P>
) _  k- f7 ]+ f$ W2 Q, k' A<P>You can use one of the following constants for the type argument. </P>1 S0 p$ U8 N! B
<P>  </P>5 S, E' f' ]: k$ a0 ~6 X* d# c- |
<P>Constant        Description </P>
; j6 o! }3 c/ a" `+ {! D% _<P>  </P>
! B0 }( t) L3 r0 W# L<P>  </P>
* \/ m# y. |4 }6 t/ S% V3 v<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>
, a6 p) b2 b3 g: }, a3 |<P>only). </P>* x+ j. y8 T) h8 {
<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>
$ L( `" f2 q4 `% l* [<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>+ L+ N* B5 c" ]! z5 x2 g7 R
<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>
9 l2 N: o9 L4 z( q' G- C<P>ODBC keyset cursor. </P>, c+ a6 f6 q6 V2 B" w* X
<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>, t, c) v* b/ e6 o  u/ T
<P>ODBC static cursor. </P>4 R0 _0 j) A7 \+ f- W) }, Q
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>
2 v0 j9 x; H5 J/ {, t- j<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>
; a  J9 ?3 \4 v; H9 Q<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>
, J1 q. H" C* O0 q<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>
# e& @3 |: k9 I( V7 c<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>
8 O1 X; O  t7 d, c: ~<P>y. </P>
" C& C; i2 [  t<P>  </P>
0 x# C( R- I5 L" }2 i, y<P>You can use a combination of the following constants for the options </P>
/ J4 ?6 p( b, x  z<P>argument. </P>6 M2 ?+ i; K' ~  u
<P>  </P>4 J. L/ k; o# V: T4 N6 s, d+ c7 L4 K
<P>Constant        Description </P>8 ], y( A; \6 l4 k! p
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>
9 D% \4 u( R/ c" p& K3 c<P>prevents them from editing or deleting existing records (Microsoft Jet </P>
* X" ?7 n2 R, k3 J0 s! X<P>dynaset-type Recordset only). </P>% P9 W9 i+ z- L8 ~
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>. p+ z% S6 h0 [7 Z
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>
# |3 F% F3 ~! V4 B- I/ e# v& E<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>% z5 K6 }( f, L" I
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>
1 ^8 ?5 `1 z) h, w5 T<P>useful in applications where multiple users have simultaneous read/write </P>
) k' J7 G3 A  |0 ^0 R<P>access to the same data. </P>, l+ p  d* G* p0 A) ?+ [/ C" ?
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>
$ n$ H( G6 ~% V$ f, V<P>Jet Recordset objects only). </P>* V/ p3 c! x! `! m
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>
1 U1 j% L! S2 S6 q& J; x<P>table-type Recordset only). </P>
9 s/ `- M3 b' U: T/ M) b<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>- S) S" @( V& y; r% C
<P>Recordset only). It is provided only for backward compatibility, and you </P>5 f% y, l1 n( e1 G$ Z0 r
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
( X' N& [5 n' k5 J  w$ N<P>using this option. </P>6 ]# B, R1 F! M4 ~  b- W5 _5 V* m
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>; e% W7 [6 ~- L8 N5 U
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>0 e' |! G$ x4 p& r* I; |9 A" z# x
<P>option, which is provided only for backward compatibility. </P>
! k; C* Y- o5 b# v/ e+ b<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>/ }. t  I8 ^# k- _: r- d) }
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>8 h) d6 _1 w, \) y. R& ?, u
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>5 ?; T3 U& N8 q6 I& m) ~
<P>not opening a Recordset based on a parameter query. For more information, see </P>5 [. ?- ]! c" U9 i' O
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>- ~; G: Z4 d, K5 L! ^. E
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>- ^: I8 v) s7 R. w4 R) j/ h4 y+ L# {
<P>snapshot-type Recordset objects only). </P>
# M- t# Q1 ]! M6 w- E( o<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>
2 W# y( C" m. k, I<P>snapshot-type Recordset objects only). </P>/ r' ?6 p: d- R8 H& `- R4 y
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>
; N' ~  J' N9 a* J  v<P>and using both causes an error. Supplying a lockedits argument when options </P>- S- g. C  K, R  o- M9 v5 X* d4 G
<P>uses the dbReadOnly constant also causes an error. </P>- u8 s0 \" G$ m0 C$ k
<P>  </P>- L. t3 [9 s* U, U
<P>You can use the following constants for the lockedits argument. </P>
/ x' P% [. h9 [/ e% W<P>  </P>9 j9 m! m, G4 N+ p5 q
<P>Constant        Description </P>1 U8 a8 I0 ^  Z/ |, `. V
<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>( p% Y  M) m5 V- k5 M$ J
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>) B7 |! V% X5 d: x
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>
. E7 ~& |9 A, P- ^. _2 K( ^<P>run-time error occurs. </P>
/ O2 _' \: z+ t% U4 B( {<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>
4 v1 W5 O# ^( H8 |# z# |2 L9 o<P>the Recordset in a multiuser environment. The page containing the record </P>
! M( U" F* F: t' k<P>you're editing is locked as soon as you use the Edit method (default for </P>
- t0 V2 ^# e' ]6 }6 R9 T<P>Microsoft Jet workspaces). </P>6 s) X- W) N# P5 c! ^8 F! o
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>% U6 k5 P% W8 M0 k
<P>Recordset in a multiuser environment. The page containing the record is not </P>
$ Y- o% y3 |7 W$ T9 C/ x' b( [<P>locked until the Update method is executed. </P>
# f* \& \+ z  U1 s5 g6 [+ U( ?<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>
1 [  _0 e, T4 F4 v4 F; _5 |<P>workspaces only). </P>
9 G# y0 w# Z2 u; m( e! ~+ [. h<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>
/ l6 ~0 f; z2 v<P>only). </P>, H" M7 e+ Q+ Q1 \
<P>Remarks </P>
7 g+ t9 y/ k, C<P>  </P>
8 i. S2 }3 `7 R2 f<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>
4 r( v. m; A  k' x) E" m<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>' l% E6 r/ e4 |! V
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>
9 M  n. V& r- B% [! A$ w<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>
, b& B( S/ M) ^+ u- l- x7 U<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>3 ~. ~- R6 T6 Z+ u& E
<P>data source, you must first set the Connect property of the linked table's </P>
: M+ m. w/ m# t7 y* G<P>database to a valid ODBC connection string. If you only need to make a single </P>
, j  B0 d" T- D% z" O5 P+ a9 A<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>6 |7 ?1 Q8 c% s8 Z& f
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>- P$ q, N/ u9 R2 G
<P>argument. </P>5 }, R' L" p' X! n) {4 q
<P>  </P>) i& t% u5 ]) @4 T7 E
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>
3 O! V( R) V8 B, x) d) D2 S<P>is of the same type object. If object </P>: P) n4 \& M# @. z: o
<P> refers to a table-type Recordset object, the type of the new object is a </P>
; R, G, S3 }" O6 g; _* I$ e) ?- r. |<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>
9 c* y6 `2 W6 D. r5 V" C# }3 J<P>杢ype or ODBCDirect Recordset objects. </P>+ w& x" r1 |, K8 T3 L) k& u
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>
$ O! J+ O' [0 z  H* A- q$ l0 V; P<P>select query in the source argument, such as </P>8 u* r8 l! ]0 _- I1 X, r4 K
<P>  </P>
# |( s$ f1 R# H; M+ F<P>"SELECT LastName, FirstName FROM Authors </P>  P5 ?+ c) z+ p6 f
<P>WHERE LastName = 'Smith'; </P>
$ \( w4 ], m4 f) P9 L9 g  L+ m<P>SELECT Title, ISBN FROM Titles </P>9 s* M! b& V/ U5 V: H
<P>WHERE ISBN Like '1-55615-*'" </P>
( u+ ]" s: r9 z: ~<P>  </P>
$ {" i* E! {' ~6 D: }3 a<P>The returned Recordset will open with the results of the first query. To </P>/ b- M7 ^+ b' T8 \% S" U8 h
<P>obtain the result sets of records from subsequent queries, use the </P>) b1 ~5 L+ ]( k, r2 o4 b1 y; S: u; w
<P>NextRecordset method. </P>
& b% K* o) W8 \5 H+ ~. ?<P>  </P>
* t, O* V6 V/ O3 w9 [<P>Note   You can send DAO queries to a variety of different database servers </P>
2 G2 s( @9 m* d3 v<P>with ODBCDirect, and different servers will recognize slightly different </P>
5 E- a7 T6 H7 y9 B<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>* a& p# Y8 z) [6 O
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P># H# b6 u' J5 v/ z4 x; A9 j5 J9 e
<P>included through the Help menu. Be sure to check the appropriate reference </P>
5 Z2 g  v9 U4 L$ c6 j4 f<P>documentation for the SQL dialect of your database server when using either </P>
2 m$ |* F8 w1 [' w) Z0 Y$ J$ B5 g! L<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>: U0 W% q+ Z% l. y1 ?
<P>client/server applications. </P>
5 i. R* b& S8 z8 J# Y<P>  </P>
) [- x) ?7 B8 {4 [7 [<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>
* y; ~9 B/ a% r- t# i<P>trap changes while two or more users are editing or deleting the same record. </P>
# {' l$ ^3 Q# b3 \- q<P>For example, if two users start editing the same record, the first user to </P>
7 [& Y) q" _, p* f' F( Q<P>execute the Update method succeeds. When the second user invokes the Update </P>
. Y! j9 r. k0 r) G<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>
9 }6 j; `) I; k; @( E& x7 f<P>the Delete method to delete the record, and the first user has already </P>
) I2 |* }3 g1 A) Q. g; Y- g<P>changed it, a run-time error occurs. </P>
/ K. B* k. X5 T# G% j/ I<P>  </P>! T) K5 k4 j: g4 i0 G7 `+ M
<P>Typically, if the user gets this error while updating a record, your code </P>
) J9 P+ ?4 o) N( a<P>should refresh the contents of the fields and retrieve the newly modified </P>
8 z/ M( \# @' v2 N9 \<P>values. If the error occurs while deleting a record, your code could display </P>1 ~6 D2 z5 m3 Z6 Y% Y4 q) j9 O
<P>the new record data to the user and a message indicating that the data has </P>2 V. v" a6 U/ {( u2 j
<P>recently changed. At this point, your code can request a confirmation that </P>
. H' `0 [% {. O  t# t7 q<P>the user still wants to delete the record. </P>
2 `- x$ T6 m& A; d) j6 ?* x<P>  </P>
/ M) {" X7 V" A, l5 ]0 E* A9 y* U<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>
' c, W  |- b& Y3 f, w3 b. Y<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>
' n5 h: w8 e- S  f- n# E9 w, N<P>later) table that has an IDENTITY column, otherwise an error may result. </P>
1 n& [/ y1 _5 x8 z# j/ n- ~5 F<P>  </P>
3 ?' T; @3 D4 P" V0 E1 S<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>. L. |4 A4 d2 ~; T& M2 G
<P>the dbRunAsync constant in the options argument. This allows your application </P>
0 g% O8 O2 Q- s" e4 g<P>to continue processing other statements while the query runs in the </P>6 ~6 x0 }. g: ^, K5 k, \% `5 ]' w
<P>background. But, you cannot access the Recordset data until the query has </P>
8 v8 U! d% w9 e% `0 }<P>completed. To determine whether the query has finished executing, check the </P>6 g( u+ M; Q, ^6 x
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>5 k: C- j; L$ t6 {3 G1 F7 U
<P>complete than you anticipated, you can terminate execution of the query with </P>
' i3 N& [9 o7 g<P>the Cancel method. </P>) ]0 C/ r( Z8 {9 b; |  L: i
<P>  </P>
; e" J! G4 d7 V$ |9 {* ^! j<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
4 l3 u* m" N9 P) S<P>connection is busy with a prior </P>9 C& t  u7 Z8 [( J$ w/ ^
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>
6 Q- F2 E- W: ~<P>ODBCDirect, if the server supports this. Another solution is to fully </P># o8 e4 W" W4 {/ A/ j! [
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>
2 n* m# t/ U! [" Z<P>is opened. </P>
2 @4 ?* @. B1 r/ X# S<P>  </P>
9 l& A" ?1 ^$ P3 \  t2 @<P>If you open a Connection object with DefaultCursorDriver set to </P>4 @; e1 E% H  {4 Y
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>$ H3 e5 S% M' a! p8 @7 t- k! j
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>
  q0 A/ i, }; ^& V  ?<P>h in the lockedits argument to enable update caching. See the Update method </P>( [  b8 \- z( {0 l4 i
<P>topic for details about how to write changes to disk immediately, or to cache </P>8 b9 C* I* i" n/ R. J9 S
<P>changes and write them to disk as a batch. </P>$ r8 B& H  m* B$ a$ x0 g0 z
<P>  </P>
$ t% ?" k4 |9 s) M<P>Closing a Recordset with the Close method automatically deletes it from the </P>
8 ^3 p6 A; K: E0 p+ F
3 m( m: k4 G) N  B  K: N0 G<P>Recordsets collection. </P>8 U" Q" a1 h  A$ f6 q5 A% c
<P>  </P>% r; z; I- m6 ^+ N; I( F
<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
) V9 u, ?8 c$ T& ^5 N6 r0 Y<P>with a non-integer value, and the system parameters specify a non-U.S. </P>1 b  `' V. H6 f8 v4 z1 D
<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>
2 |% f; t0 i) f9 B! y9 ]4 Q<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>. a7 G7 l( ~: V3 ]6 ]
<P>Recordset. This is because during concatenation, the number will be converted </P>
- _3 a/ Q6 D0 `$ B# M<P>to a string using your system's default decimal character, and SQL only </P>$ r$ Q# E2 M, 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-4-10 07:38 , Processed in 1.737028 second(s), 52 queries .

回顶部