QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>
# Z  @, J8 j+ P& P<>Creates a new Recordset object and appends it to the Recordsets collection. </P>
- p( F7 O/ K8 ^  z( Z0 B<>  </P>
4 g2 V$ q. m3 o. B- E( ~6 c  ~<>Syntax </P>
) w& l/ A* M- j# v1 d& T  ?2 l<>  </P>1 F+ Y! o$ Y, ]8 D' t  R8 s! }3 E
<>For Connection and Database objects: </P>
& p+ l9 [3 S9 G4 C<>  </P>
1 E( k; g0 q' m, ?; z<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>6 k" P& u: r# Q/ v6 \
<>  </P>9 K" ^6 E7 \- p6 @
<>For QueryDef, Recordset, and TableDef objects: </P>
5 F# n9 D: e4 u- _, F4 n7 `<>  </P>
: P. k3 b" e6 n+ }<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>
- i5 r6 Q% b, j7 ]- r<>  </P>. k! b% e+ ^7 t" u2 H+ B3 \
<>The OpenRecordset method syntax has these parts. </P>
6 a  n1 t! T% H$ Y. A<>  </P>/ m" p. P; m* y8 `
<>art    Description </P>
; P2 p2 |8 @5 R' i& v; r<>recordset       An object variable that represents the Recordset object you wantt to </P>0 M4 z! R5 K" ~+ f
<>open. </P>
1 \; N) H9 C2 v, u, X4 W0 G<>object  An object variable that represents an existing object from which you </P>* u' S7 u* b' X0 y9 K, X
<>want to create the new Recordset. </P>7 L. Z/ ~/ {5 ]; z+ o% r" c3 J
<>source  A String specifying the source of the records for the new Recordset. </P>
% y6 q  u# R/ H% c<>The source can be a table name, a query name, or an SQL statement that </P>* S# t! z* C. e; H
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>8 z: t" R: c' d/ o, k
<>the source can only be a table name. </P>6 }7 |* L/ k, q: b8 ?
<>type    Optional. A constant that indicates the type of Recordset to open, as </P>6 S! U& p4 L8 w8 @$ E/ b
<>specified in Settings. </P>
. N0 g- \- }. O$ J<>options Optional. A combination of constants that specify characteristics of </P>
4 c% N' o5 \* U# P' ^  W<>the new Recordset, as listed in Settings. </P>. s/ i% B  Q4 d- O, E
<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>* N# |# y& [2 ]; m+ ?' e3 U& u! N
<P>as specified in Settings. </P>
. K/ F! O0 f1 ^/ p<P>Settings </P>
, N9 f* g' f& v% t' I. s2 i6 H- n<P>  </P>; p$ e3 J, V6 L" y# P
<P>You can use one of the following constants for the type argument. </P>, ^3 ~7 F: l9 O; s6 z, o
<P>  </P>
: D$ r  x% W: `( o9 F- ^: m1 ~<P>Constant        Description </P># ^' m4 ]2 }9 ]/ X; z) ~0 L
<P>  </P>+ l4 }& L- F+ A# Y+ O/ S, O7 j
<P>  </P>; B/ {- ~1 @5 p0 o0 Y  k" T. N; V
<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>
0 m4 D0 d' m$ f<P>only). </P>
/ ?6 Q& L8 [# w& v3 l6 r<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>
; d7 @2 }- V6 D! `+ \/ Z, ?<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>
% v' @8 i" L6 Q' V7 [( k2 h# m& r<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>3 O4 g# d/ E& _3 K
<P>ODBC keyset cursor. </P>( ?6 V  Y3 k- k0 W7 i$ n! ^
<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>
- j+ E+ Y+ f" Z$ B<P>ODBC static cursor. </P>; k0 J( }- u& ?8 }) K7 b
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>3 i$ p6 ~  k1 j/ p9 i
<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>2 I/ N* m* b; t# a, X; F6 B7 i
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>
4 \9 |2 ]. H- I9 P- A" {<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>
; t2 ~; Q7 p$ m* j<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>% c- q; l  I! V9 X7 B
<P>y. </P>0 j% v+ R3 g# s' _0 c4 X
<P>  </P>
  Y) W% E# [8 i& d( {0 N- `) F- B<P>You can use a combination of the following constants for the options </P>
8 v& K- ?8 v2 Y<P>argument. </P>, u+ z0 s- F7 u& S: @" Z, n2 G$ A/ S
<P>  </P>
, G6 I/ i# \; v6 I8 R: C. d8 h9 G<P>Constant        Description </P>  C" M8 A) J! B1 m! f) _4 U' s
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>6 X5 C8 F- H, e2 e. |$ ~, l$ K
<P>prevents them from editing or deleting existing records (Microsoft Jet </P># h" H& Z$ A) D0 ^  b- n# O+ I
<P>dynaset-type Recordset only). </P>
$ k+ q/ B: b8 Q# v4 _; e  m<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>9 ^* c6 E' A% W/ |+ s' C
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>
9 f! t5 }: Z9 e1 b  K3 q<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>
) U4 E0 s1 v4 r1 x6 S! `: y( |* F$ Y6 ~<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P># E, }7 P  K) {2 X; s  E- k% X: q) g1 Y
<P>useful in applications where multiple users have simultaneous read/write </P>& {0 e$ j! G$ v! m
<P>access to the same data. </P>
! B8 P  F3 f# R) R<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>
( v9 L) N& B( g0 ~5 _5 R<P>Jet Recordset objects only). </P>& w" X. d" m3 P  B% Y' Y
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>
( B% U0 _) l3 b+ n; Q1 D<P>table-type Recordset only). </P>+ z& r" b. T$ \) j) G0 C
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>% L* F2 G  _& a
<P>Recordset only). It is provided only for backward compatibility, and you </P>- n, q: T4 ^5 H  d1 n
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
; w) B1 E. \! `$ b3 {' ]3 V. b# Y<P>using this option. </P>+ {& `- H9 `8 p
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>
! y" V, W4 \( k0 H1 d* W1 v2 t. O, t<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>
7 n4 y" w$ |. E7 v0 f1 R<P>option, which is provided only for backward compatibility. </P># Y# w6 `4 W5 p( k/ B9 H2 ^
<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>
! v" [/ b5 c. o<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>% |- O5 Z' h6 e: I' x: z
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>
9 L! ~4 b' z, t) T' W) P$ ]3 E3 ^<P>not opening a Recordset based on a parameter query. For more information, see </P>
. E8 }. C- d& T2 ]<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>
) b: h$ o% m& D1 c' Q$ Z' n<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>1 {* i# T" ^: D/ H* C) _0 F0 Y! c0 _" l
<P>snapshot-type Recordset objects only). </P>& j* g  R3 J+ q( n) m; V# X
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>
% u% W7 g$ S7 J/ D3 B<P>snapshot-type Recordset objects only). </P>& K( t% E. f" K
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>
. _' q! C5 o- a$ w8 [<P>and using both causes an error. Supplying a lockedits argument when options </P>
5 @6 `9 h* S  [, {* Y. R. D/ D$ f<P>uses the dbReadOnly constant also causes an error. </P># j8 v' C4 B+ _) t1 i1 e
<P>  </P>
! l1 B9 r! k2 |; B$ c1 K/ e<P>You can use the following constants for the lockedits argument. </P>' V, ?$ k' g% g& e& H
<P>  </P>
8 [# Z  T4 d; c5 R: L9 \<P>Constant        Description </P>: \  R" S( z- G+ V) f$ i. l3 T7 h
<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>, y, Q" a: @$ ~" c- B/ F
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>  c, k7 {! Y& Q8 m0 m" a
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>! d9 p  J) o/ i5 |* O' u5 F) M
<P>run-time error occurs. </P>
+ u( w" ]3 G1 H; i/ s# C- Z$ B; {<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>. A# v% m0 n/ `$ c
<P>the Recordset in a multiuser environment. The page containing the record </P>
9 w$ y; b% b* D. a, P. P* }<P>you're editing is locked as soon as you use the Edit method (default for </P>
; J4 ~3 j+ \% p+ x4 C3 }4 b<P>Microsoft Jet workspaces). </P>
+ R! Q9 r/ u4 T& C, u8 o<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>
1 P5 d) d, H: h( e/ n<P>Recordset in a multiuser environment. The page containing the record is not </P>
) }! n! R. C* e5 p9 g3 y<P>locked until the Update method is executed. </P>; V% `! M# M' f' _  p! R" e* k
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>2 ^7 g1 @/ D$ i
<P>workspaces only). </P>" v, c0 y! _7 V; G# B1 \5 g
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>0 w0 E* D& S$ r3 K8 \
<P>only). </P>% Z; C1 H, m. c' ~
<P>Remarks </P>
3 t; {4 [+ d  \4 u, P' B<P>  </P>% L+ V" n' [9 Z5 }4 b4 k
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>% U) |: o6 Z% ~) g
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>
! P: C# H& T3 L# x3 j9 i3 r9 n<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>$ j- c8 [. G0 `+ M- Y, c
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>
4 n- @% `- J1 }<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>" M' h) `/ {# h( }: Z
<P>data source, you must first set the Connect property of the linked table's </P>2 H1 h' ^* a# O/ A% K' g
<P>database to a valid ODBC connection string. If you only need to make a single </P>! s* v' K. ~5 U; x
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>, g. ]* q0 T5 K; b9 m* c3 q6 m# T
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>' R2 N4 L5 K# E& b
<P>argument. </P>) V3 a$ q% p' v5 i" y" u
<P>  </P>7 h: O* P' R' t
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>
1 `  O/ o4 G3 l. _3 z' `* |<P>is of the same type object. If object </P>
: B5 W- B  }; J- S% h1 O<P> refers to a table-type Recordset object, the type of the new object is a </P>9 s' \* Y& y' W# _. H2 a
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>( ]6 i, {* H% S: D2 R; b1 U
<P>杢ype or ODBCDirect Recordset objects. </P>
; Y# k9 ~- k9 _; Q+ M) Q9 S/ o<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>
4 q+ D: y7 }' |/ }8 U# D  f<P>select query in the source argument, such as </P>4 V  [+ a. j! ?
<P>  </P>
' ~; R# |6 \1 j9 ?" v<P>"SELECT LastName, FirstName FROM Authors </P>0 r6 B7 z( ]) K; t5 L" m& X, i
<P>WHERE LastName = 'Smith'; </P>& E& Q) l0 q- ]
<P>SELECT Title, ISBN FROM Titles </P>
$ R' Q! [/ `2 l& k7 p; {<P>WHERE ISBN Like '1-55615-*'" </P>$ ]9 y! l; |9 B
<P>  </P>1 w7 Z  m3 D$ G6 J. @/ i
<P>The returned Recordset will open with the results of the first query. To </P>8 ~$ Q7 I, u$ e! w0 j% i) H
<P>obtain the result sets of records from subsequent queries, use the </P>
. s! n; d' O8 c<P>NextRecordset method. </P>
2 k- f$ k, w) h, ?. I! ]. s<P>  </P>
- ^% K+ x' s( Z<P>Note   You can send DAO queries to a variety of different database servers </P>
8 j" r3 N, f4 ]: S<P>with ODBCDirect, and different servers will recognize slightly different </P>/ P# c$ Z3 V- Q; B: `% Z" b6 p# I
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>. A0 H5 D. T" e* F1 q
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>
8 `2 o3 X6 B# p$ Z$ Y<P>included through the Help menu. Be sure to check the appropriate reference </P>) ]) }; }) `$ Z2 ~# h- A6 q. f
<P>documentation for the SQL dialect of your database server when using either </P>
; ]1 \1 N0 G" j4 T$ p<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>
# h- t1 J* b' ?7 J4 ^<P>client/server applications. </P>
7 f% x) i8 e# z% B$ V4 i<P>  </P>. L& S# q. p, J9 M' l
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>
$ j; D1 C  b! P( V! f: k2 R<P>trap changes while two or more users are editing or deleting the same record. </P>
1 n7 s, x8 ~& y! A% n' {<P>For example, if two users start editing the same record, the first user to </P>
9 C) d9 \) P- K7 k" E; @" }  b<P>execute the Update method succeeds. When the second user invokes the Update </P>
3 i8 i8 ~! _# S) V: z" }" F. K2 g<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>" V( q8 w( Q' _  b
<P>the Delete method to delete the record, and the first user has already </P>3 r" t$ S; O  U8 t; x2 c1 j
<P>changed it, a run-time error occurs. </P>
* {! r  {$ |4 O7 b0 S8 b& E" B<P>  </P>$ C# q& E& k$ g' W
<P>Typically, if the user gets this error while updating a record, your code </P>* p' @/ y4 k7 T( z
<P>should refresh the contents of the fields and retrieve the newly modified </P>
$ z4 j4 c0 X4 y6 P. }<P>values. If the error occurs while deleting a record, your code could display </P>
7 B# |: s0 j( `/ x- K; L<P>the new record data to the user and a message indicating that the data has </P>
  g! i- J6 E' Y# L0 B0 a<P>recently changed. At this point, your code can request a confirmation that </P>
& m: H! i; V+ J. r" {, B& l<P>the user still wants to delete the record. </P>  S  `% s  _: l! L
<P>  </P>- y+ @4 R% ?5 v; b- r  \# D
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>  n2 D: c5 m  B: X
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>
" T+ N5 S! Y# G. J( X6 }+ F) P<P>later) table that has an IDENTITY column, otherwise an error may result. </P>3 ]3 u% i9 m4 x5 X/ H" L; @
<P>  </P>7 N6 H+ p0 ?( E5 a
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>9 c3 g0 z3 f1 H3 F
<P>the dbRunAsync constant in the options argument. This allows your application </P>- }( k6 B  {7 R/ _, _
<P>to continue processing other statements while the query runs in the </P>+ B+ B. Y# t1 P- Z* o% M
<P>background. But, you cannot access the Recordset data until the query has </P>9 I8 l) Y! E; ^0 C  b! N! @
<P>completed. To determine whether the query has finished executing, check the </P>
3 m; ~7 u# G2 D<P>StillExecuting property of the new Recordset. If the query takes longer to </P>& R7 \1 a+ h. P/ b
<P>complete than you anticipated, you can terminate execution of the query with </P>8 _! h* T  i2 d
<P>the Cancel method. </P>  c# q4 e6 P# L9 J
<P>  </P>
+ s$ t7 L/ [$ p7 P<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
. ?8 U- ~5 L' w* Y* t<P>connection is busy with a prior </P>% U, s* K  a* _7 {% e
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>
$ o" W0 z5 J3 @  v  D<P>ODBCDirect, if the server supports this. Another solution is to fully </P>
0 I9 l; b  j1 r1 }<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>* p4 w- Z1 V* A1 X9 k' W
<P>is opened. </P>. E1 D/ |4 v/ p" U
<P>  </P>
9 I2 g1 s$ C" l, y6 F3 f<P>If you open a Connection object with DefaultCursorDriver set to </P>  [5 E3 C" h6 |0 s6 L+ I- @  ]" C
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>
- U) F- d% q4 L6 b<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>& @8 Z; q* W: \3 Q  l& E+ z
<P>h in the lockedits argument to enable update caching. See the Update method </P>
  h3 V/ A" ?3 ~' [" V1 [% n+ U<P>topic for details about how to write changes to disk immediately, or to cache </P>6 r  D6 n, ]2 v* {% u& E8 t
<P>changes and write them to disk as a batch. </P>
5 A4 y( s; k. A$ t0 u3 w$ l! N<P>  </P>3 V( B3 y7 Z# _- [5 h9 w' U& H
<P>Closing a Recordset with the Close method automatically deletes it from the </P>* J% x- y9 G& b7 k1 V/ T
* b! ?" ^1 {1 W3 C) L! A
<P>Recordsets collection. </P>" E) ~& U8 k2 m0 s$ _/ X
<P>  </P>
7 f+ h1 u4 a6 u. A<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
/ I& A$ {+ `8 u+ x) T+ Z7 {<P>with a non-integer value, and the system parameters specify a non-U.S. </P>
( t, S" K. r1 |) h$ z<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>
& C1 E! B; }- {& l3 X( n4 L; X<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>
; V4 u" @$ g4 }4 `* _' o2 X; \<P>Recordset. This is because during concatenation, the number will be converted </P>
- p0 X% o$ n* T<P>to a string using your system's default decimal character, and SQL only </P>
% |& }& q, M( A2 }+ G, i4 J5 a( r7 e<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-11 15:30 , Processed in 0.404708 second(s), 52 queries .

回顶部