QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>
& H% G; O) @( Z<>Creates a new Recordset object and appends it to the Recordsets collection. </P>
! L: ~  A6 m: E9 {3 U  }. C2 i<>  </P>' {! ~. G2 I3 n  w' Q; \
<>Syntax </P>/ X" p4 u1 g3 ~8 U6 d: t6 W9 q# b
<>  </P>
3 l/ g+ Z5 v# J<>For Connection and Database objects: </P>( w% f; L2 u% R- x4 m
<>  </P>0 u7 y" G9 n4 P& H. h* s
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>( p) S: n; j% s; r5 d" U1 m( u
<>  </P>6 o/ G$ K( s% H7 h3 g; E
<>For QueryDef, Recordset, and TableDef objects: </P>' i1 O5 W" [8 U, F' N% f+ c( o
<>  </P>
8 h/ a% x; K3 X0 r+ b" o% N" I<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>
' b$ j9 Z$ i, L9 ^! ~4 E* F7 y3 O<>  </P>5 z$ B  g4 y0 R/ x0 k1 H0 h5 @9 b/ ~2 i
<>The OpenRecordset method syntax has these parts. </P>
+ P+ w/ E7 Z- D; G9 r: E<>  </P>0 c, t0 L$ A3 ?! r
<>art    Description </P>
( A9 k6 e' f7 g8 q) G<>recordset       An object variable that represents the Recordset object you wantt to </P># V, D1 B& I' u& K
<>open. </P>
) i; v3 U) a. ?  `; _5 v6 ~! P<>object  An object variable that represents an existing object from which you </P>
1 {5 f2 y5 h; _9 w* N<>want to create the new Recordset. </P>
# g- R1 f) ?( P# i<>source  A String specifying the source of the records for the new Recordset. </P>
5 [5 z, J, L3 K: c( K3 x- Y<>The source can be a table name, a query name, or an SQL statement that </P>" H7 o  @) n* m. V
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P># g: m1 D4 z# {3 @+ P" j" }
<>the source can only be a table name. </P>
+ D' A+ x! a, ~# d: v( V& K<>type    Optional. A constant that indicates the type of Recordset to open, as </P>. Y: r. }7 E. s/ q1 U7 z
<>specified in Settings. </P>
. _) q8 k1 I1 T) q7 z# O<>options Optional. A combination of constants that specify characteristics of </P>/ E% H% f- d! I5 w; s, ~: o6 o$ t
<>the new Recordset, as listed in Settings. </P>" `& u* D; I: `, ?
<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>4 _3 B$ ?. `4 C
<P>as specified in Settings. </P>. ?, @, `: K' N/ a8 h, s
<P>Settings </P>
) y/ h) Q% n! v$ y  J0 E/ i5 a# w<P>  </P>
# Y' Q. H- d. G0 o) d6 [& K<P>You can use one of the following constants for the type argument. </P>) V3 {% l) e( m4 D
<P>  </P>" w! [' o; q; D# [1 s& R( n
<P>Constant        Description </P>
+ P5 s0 f; F6 n' G: B/ |* s- ]- _<P>  </P>% O. j5 X! k+ H# b  F9 q
<P>  </P>
' `3 E+ i. r& z- B<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>. A8 [! X4 V. T4 l( Q) v" y/ O
<P>only). </P>
1 c2 R' `1 }+ m# s  G  a4 E<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>5 `; r% G4 J* [1 U+ g+ v! c
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>
8 a0 V0 ^% C* G, y<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>
0 s( s9 I+ U' P8 a( S<P>ODBC keyset cursor. </P>  `1 t+ }+ J6 W- L' H
<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>) o0 D8 ]2 V8 B, z! A: C0 H. O
<P>ODBC static cursor. </P>
. p7 V6 L6 b* O3 E1 A$ f<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>
/ C  X  |8 s- F( l' E/ _<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>! z3 X3 o$ C2 e$ ^. e3 S
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>
9 l( W& b9 V$ H6 E6 F8 K<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>
. F. i8 }# A% t' i+ N  a<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>
2 A) G7 f( H. l; a. K' k<P>y. </P>- d! C. W7 s1 D( U& M
<P>  </P>
) Y1 K, i' S2 \7 Z, [* ^<P>You can use a combination of the following constants for the options </P>
" d1 G2 h" x+ Y* t" |! A  G<P>argument. </P>; S1 i. F) P1 r0 T  _& [0 [. q' |2 \
<P>  </P>* ]' {' y' y* g: b
<P>Constant        Description </P>7 v% i( B. ~3 m9 W& g! ^, r
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>
0 y9 O& _" {7 U0 c' x; U  x7 L<P>prevents them from editing or deleting existing records (Microsoft Jet </P>9 l1 L) B6 K* p: e8 q+ t' r
<P>dynaset-type Recordset only). </P>& J4 s( t' G7 d. A
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>: H9 S" V5 N' f5 @% k$ C1 }8 o
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>
- N+ f8 B, B3 U7 o1 F- K<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>  `9 T0 ]' Y1 N7 }$ ^" ]
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>- r0 _; `, }/ \9 O) H8 q
<P>useful in applications where multiple users have simultaneous read/write </P>* Q& X  E6 Z+ g' Y) Y/ `% T1 _' N
<P>access to the same data. </P>
3 ~$ e  B5 q" _. b+ n5 B' `<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>5 L% k; T  ^/ s5 J( }- \# m8 f, K
<P>Jet Recordset objects only). </P>& b6 H% }% }) ?
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>
4 Z8 |( G) S7 L2 [. [& ~# v: S<P>table-type Recordset only). </P># y9 Y) L- X! U& q; ~8 b
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>9 [6 b& k( q' @. k: ^- O! f
<P>Recordset only). It is provided only for backward compatibility, and you </P>
) ?( E2 N. Q1 l  V* M9 r) {<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
9 u/ U8 K# ~5 u4 ]5 A( n5 T. `1 R<P>using this option. </P>$ l0 [3 O5 J, N% c$ e
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>
4 ]) z) F1 T  E# _) x3 X6 G<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>
: D5 j: G: `0 {$ f8 I<P>option, which is provided only for backward compatibility. </P>+ ?+ Z& s0 {/ L
<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>6 t; y7 E) L- _1 |  y- I
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>) W6 `) K( N9 B9 i0 X+ h7 v
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>
- X8 l- W: _  E: a: N% \<P>not opening a Recordset based on a parameter query. For more information, see </P>
& s1 }$ B$ E$ e% _2 @% X<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>
- z  X6 t) `$ A<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>
. K+ [9 G% Q% P1 m# e& ?% D<P>snapshot-type Recordset objects only). </P>
+ ]0 f0 M( H+ t2 U9 J* V3 v- k<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>
$ I* r% V- m# p! B<P>snapshot-type Recordset objects only). </P>- W/ A# Z: W% X
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>
. k" H; V5 [6 ?& z, y<P>and using both causes an error. Supplying a lockedits argument when options </P>
' H) D! l, L$ K( P<P>uses the dbReadOnly constant also causes an error. </P>
2 \; @& w# i- i/ M6 Y/ I, E<P>  </P>+ K6 z; n# h. ~5 ]8 n; h3 c6 s
<P>You can use the following constants for the lockedits argument. </P>( Y+ i! R( N% J8 S9 k" d# N! s6 i
<P>  </P>( H+ F' c* y9 n# ?) S+ _
<P>Constant        Description </P>
  j0 C5 B( W0 F# N* ~. Q<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>$ N2 J/ ~  c8 F
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>4 ?# }! R9 R9 E# _
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P># m$ `* f4 W1 n
<P>run-time error occurs. </P>' J* s( H' m. A- y2 p8 A
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>
/ ~2 V9 q* ]. L! f/ D<P>the Recordset in a multiuser environment. The page containing the record </P>
; L4 T+ }1 K  b! r* H<P>you're editing is locked as soon as you use the Edit method (default for </P>: H  X& x5 ^9 J
<P>Microsoft Jet workspaces). </P>' }8 ~& s' y$ w
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>3 s) k) F! G0 w/ _9 v
<P>Recordset in a multiuser environment. The page containing the record is not </P>( C3 Y% s. d' [! Q
<P>locked until the Update method is executed. </P>
6 L; q/ T4 \3 l0 P5 d. v1 f<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>5 j8 A$ [5 \8 U! E6 W1 Y$ i
<P>workspaces only). </P>
' x0 a' j5 g" j0 L" a  A" D<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>3 @  w6 }$ ~. ~; |
<P>only). </P>
. G' f  J  S1 [- Y! @: P, N<P>Remarks </P>, m1 f: r! I4 D; X2 z
<P>  </P>
5 i: B) e/ i$ M0 u% Y) c<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>
' u) d2 E- a3 {4 S  @+ k<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>. h0 X: y% s3 L* o2 E2 u  Q( S0 _
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>, I) C: R$ l- s7 {/ z
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>
( `/ P; n  h- R. J4 c<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>
  ?/ z8 g; B: d9 N<P>data source, you must first set the Connect property of the linked table's </P>4 }* f% ^) G6 P5 B) W5 i
<P>database to a valid ODBC connection string. If you only need to make a single </P>5 g* ~7 Z8 g$ P& l- C# C
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>0 z8 _* a7 \5 F# o- |' L
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>0 n1 Y2 \" @$ S7 ^  I- K" r  O6 I
<P>argument. </P>
! b: J3 v9 d8 B0 N/ B<P>  </P>
5 T9 e8 }3 R% L5 M. l% k<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>; m# |& _7 x( N! l% p/ X/ k+ J$ N4 r
<P>is of the same type object. If object </P>  O/ k& l5 o/ z
<P> refers to a table-type Recordset object, the type of the new object is a </P>1 x" ?" H) _9 {/ P
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>
% B  Z: ?/ S' n; ]8 J: m<P>杢ype or ODBCDirect Recordset objects. </P>
( Q" M4 h5 a8 ]0 M2 o8 m<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>5 N% p' K( \: }
<P>select query in the source argument, such as </P>
$ D; c" d8 X3 l) p- l( V<P>  </P>
) e; Z7 o: P* ?" S! n/ X5 B<P>"SELECT LastName, FirstName FROM Authors </P>
* _3 g/ w: L, j2 T4 F<P>WHERE LastName = 'Smith'; </P>) o) M7 o4 K3 s6 t  y: ~2 a4 j
<P>SELECT Title, ISBN FROM Titles </P>
% B& }' w& }- g5 `0 A<P>WHERE ISBN Like '1-55615-*'" </P>
) J7 v, S6 t$ p<P>  </P>
; t, n5 o. r0 h. S<P>The returned Recordset will open with the results of the first query. To </P>
9 w6 Y( m7 i, B+ J0 p1 V+ x- Y<P>obtain the result sets of records from subsequent queries, use the </P>
% f. w6 r: `* E1 i1 }2 A<P>NextRecordset method. </P># {( x* ?& J1 w- }) b8 O# m
<P>  </P>
1 S( d$ p5 v& V" \' ?<P>Note   You can send DAO queries to a variety of different database servers </P>/ H0 u; B2 F7 q
<P>with ODBCDirect, and different servers will recognize slightly different </P>: z- e/ l& P1 q- t5 f. Q' n
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>
# m3 t. E) e0 d; s) ^<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>
3 O+ F; K" u% |( @<P>included through the Help menu. Be sure to check the appropriate reference </P>
; o( a2 j* |- P! f/ w) C9 V0 b<P>documentation for the SQL dialect of your database server when using either </P>. g' d* g4 a- s7 M' r- ^$ B& q: a
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>6 Q& |- B8 X. {. O. \! K
<P>client/server applications. </P>! A  d) K! Q. G+ c" F
<P>  </P>
3 F: _. X8 B* G0 J7 b  [+ ^+ R! {<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P># e4 ?) v+ l2 P/ Z6 k6 ^6 {' ^
<P>trap changes while two or more users are editing or deleting the same record. </P>
& c: Y9 E* k$ x6 q' c+ f<P>For example, if two users start editing the same record, the first user to </P>4 p4 f' v6 n% D/ y" d; ~  c
<P>execute the Update method succeeds. When the second user invokes the Update </P>; l. k$ ~5 v& |% k; R/ o  a
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>9 L  E1 Z, @4 c* O, r& d
<P>the Delete method to delete the record, and the first user has already </P>
7 |# c# a0 x2 Q' ~<P>changed it, a run-time error occurs. </P>( Z7 D' S; P, V2 T+ @1 i
<P>  </P>+ p* ~# G  n, Y, X2 U8 ?
<P>Typically, if the user gets this error while updating a record, your code </P>
+ l. E' G# ?4 ^2 v. k2 v<P>should refresh the contents of the fields and retrieve the newly modified </P># `" h! C. R, w
<P>values. If the error occurs while deleting a record, your code could display </P>
/ Z, y3 E6 b* @9 _: p3 U<P>the new record data to the user and a message indicating that the data has </P>4 X) F) M6 I( r& ~  C1 w
<P>recently changed. At this point, your code can request a confirmation that </P>
4 V+ R: Y5 S+ t) E<P>the user still wants to delete the record. </P>  \/ _+ U* S0 t" x1 I% O. I& @/ ^' g
<P>  </P>. i* g1 ?: U! p9 V+ w; l3 ?
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>
1 v. L+ A6 \- i* R) i<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>' V! R) @. f; T/ h
<P>later) table that has an IDENTITY column, otherwise an error may result. </P>
: F' J7 f. }( ~& g+ `<P>  </P>
" j2 y  o$ `1 l  d<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>
1 W/ h3 W& T" W, Q0 w<P>the dbRunAsync constant in the options argument. This allows your application </P>
, K& H2 r" r9 ?<P>to continue processing other statements while the query runs in the </P>0 F4 p3 ~/ P3 p  ^' E. [, ~
<P>background. But, you cannot access the Recordset data until the query has </P>
* a, e$ E+ X; y8 c1 b6 Z, U/ `! E<P>completed. To determine whether the query has finished executing, check the </P>; U& j) o* z, V, \
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>
8 L: G. z3 T8 Q; k<P>complete than you anticipated, you can terminate execution of the query with </P>
. u( C0 A" s: m/ E/ H* A<P>the Cancel method. </P>1 L0 i; q& E0 W  K, G1 T; ^
<P>  </P>
' \2 @1 G9 ]9 j( K+ \2 m- ^! n<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
+ X5 Q0 g* K. b# P<P>connection is busy with a prior </P>0 T+ f9 `1 {7 l8 V0 m* r
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>: m( e/ k5 C! m6 F+ X" g' c* C0 Z
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>
  f1 d: b5 s8 }0 f3 |  r<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>
- m+ I: A8 E# e/ G  c4 n<P>is opened. </P>
  \: d% X$ s4 I0 ^. l8 v$ Z<P>  </P>: s. [: J, @6 L
<P>If you open a Connection object with DefaultCursorDriver set to </P>3 O1 {' R2 X  v* T. P, n
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>0 y) T9 M+ R$ W7 Y( v; b1 }
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>- z, d5 q  j4 u$ M  t1 X
<P>h in the lockedits argument to enable update caching. See the Update method </P>0 k2 w1 h. v  ]
<P>topic for details about how to write changes to disk immediately, or to cache </P>
7 O4 ~. T& k; h; T) L, U<P>changes and write them to disk as a batch. </P>
* E, T; v8 A! x9 l8 J* H: z) B( u<P>  </P>' T  s$ X# }6 u+ u1 T- B
<P>Closing a Recordset with the Close method automatically deletes it from the </P>) n' |$ l$ S" w( j- Z8 |* y

/ \; [8 ?! |+ L3 e$ J$ H7 Q<P>Recordsets collection. </P>" U6 ]( z9 d- h* i
<P>  </P>
5 C$ g+ P# C3 ?$ _& B: _<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
. @% T( i6 ^- X( [<P>with a non-integer value, and the system parameters specify a non-U.S. </P>5 e8 |# V! x' @2 j
<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>
  A1 a% d' b0 A' S" ]) K<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>
  Q4 m) ?* r7 Y: d<P>Recordset. This is because during concatenation, the number will be converted </P>
. V: S' K# i- U2 c0 k9 \: h% V<P>to a string using your system's default decimal character, and SQL only </P>3 p" _9 H2 v/ t! p- O
<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-6-12 08:37 , Processed in 0.576975 second(s), 51 queries .

回顶部