QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>
" [! A( j& K$ G) @2 D5 h$ `! l<>Creates a new Recordset object and appends it to the Recordsets collection. </P>
: k+ w# J' l1 d& A5 m' @<>  </P>
7 t) v% L2 i- A<>Syntax </P>* U: a! ]/ A. ^/ b
<>  </P>' ^0 F( z7 A* x* m2 `
<>For Connection and Database objects: </P>7 f" B+ X/ I, G7 l  Z
<>  </P>
# Q' v  y( J9 }$ i<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>9 M2 q+ E/ J. U$ K% z
<>  </P>: S$ G" r. t6 y$ d' o
<>For QueryDef, Recordset, and TableDef objects: </P>9 ?  w# a5 b( ]% [4 Y7 I
<>  </P>$ e1 g. Q7 B) _7 E* O1 s
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>& ?6 C) n0 u' y1 R, s. y
<>  </P>; y7 W1 X4 }5 _* ]# w% l
<>The OpenRecordset method syntax has these parts. </P>" v0 R3 s1 |% f$ j$ S- ?$ I
<>  </P>. o" o( i0 f& u1 A' U# f1 L# f
<>art    Description </P>0 d, @) g3 W* f! k+ j
<>recordset       An object variable that represents the Recordset object you wantt to </P>
5 z0 ]5 B; E: g( `7 I% g$ r<>open. </P>; a! j0 W! v7 z% o$ c. r6 D
<>object  An object variable that represents an existing object from which you </P>
- b$ X* s$ Y+ \<>want to create the new Recordset. </P># `- E, w* k' n; {( E
<>source  A String specifying the source of the records for the new Recordset. </P>
  B- {- ~7 r, e6 h# }+ B! J<>The source can be a table name, a query name, or an SQL statement that </P>% q/ B# e: ~! s7 f
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>
# v) E/ i+ |- ?% ?3 ^. I<>the source can only be a table name. </P>0 j* T! R8 ^8 b$ ?% q6 H+ o
<>type    Optional. A constant that indicates the type of Recordset to open, as </P>$ S0 t0 t; `$ a( H
<>specified in Settings. </P>
7 `( g6 ]' J2 R# Y  R8 h" S<>options Optional. A combination of constants that specify characteristics of </P>5 |' j3 M3 W: v
<>the new Recordset, as listed in Settings. </P>
0 l3 I/ y. ]6 Q/ q<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>
  d8 f8 v; Q' \<P>as specified in Settings. </P>
6 s4 N; W7 ], G; \. G+ Y+ y8 O<P>Settings </P>
% z( H3 k( r) d$ d% T4 N- f<P>  </P>
& l9 Z* G; x) s0 Q* ]! h9 B<P>You can use one of the following constants for the type argument. </P>) |. w7 ~- j" r' v, x
<P>  </P>
: G! t/ V7 M% M% a<P>Constant        Description </P>
# Q: u7 M, [( a4 ]% ^<P>  </P>. r# Z# Q; d6 T1 p! |' R0 I
<P>  </P>; [& z$ m9 ^! b! l! Y
<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>
; I* M# q  E( S<P>only). </P>
8 U% N# I/ c: S5 O$ y1 {0 s8 T& s<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P># h6 G1 J4 g* B2 T" l
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>
% a( b. o; p, C<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>
) i. @6 h* V# Z8 p<P>ODBC keyset cursor. </P>
8 t7 X4 k) L* i6 n* o1 [' e<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>
' w/ q4 L; p: G: f6 l<P>ODBC static cursor. </P>! e2 Q6 ~7 `9 @4 {+ y. {0 [! b' O* }5 c
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>* H8 v0 b- o6 W
<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>
( C6 }4 q$ r% F: F# d<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>
6 {: X3 F! x8 u0 \! g<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>4 l. ~, x4 |2 V
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>; a$ O6 W7 O: T+ H
<P>y. </P>
- D3 R; i* P0 y7 T0 D' r% B<P>  </P>
! P, W9 @' l% R( P! o! e<P>You can use a combination of the following constants for the options </P>: U% h2 f) _) S
<P>argument. </P>/ a, U$ K" _2 c( w1 y. n+ Q
<P>  </P>
/ B' @: P! R, V3 R2 O% t, C2 A<P>Constant        Description </P>
  Q" V9 k1 a. d' P  I( i6 o<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>5 `! ?4 v" v: Y; b0 g: L% z
<P>prevents them from editing or deleting existing records (Microsoft Jet </P>) s8 ]: }3 |. Z; ~, D+ p+ ]4 ~
<P>dynaset-type Recordset only). </P>7 E9 ]+ I, F) \: ~
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>) a% |% s# e4 L6 @
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>
, z+ T3 E; d( ?) |" L% @<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>
9 f4 j/ x! |( U+ f, h$ n! ~/ C<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>
( j6 x6 F4 @- }* l3 M" ?<P>useful in applications where multiple users have simultaneous read/write </P>7 C7 q+ f1 ^. P% x& d
<P>access to the same data. </P>
( L5 K, J9 w: T9 I5 u<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>
+ z  r# v: J2 V. ]4 g<P>Jet Recordset objects only). </P>2 A( V, e5 }- [8 o* |: E# \
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>
5 j/ [/ K2 E3 @; i; d- d# T2 _<P>table-type Recordset only). </P>* [  {% q5 w1 W4 g' }. N4 l
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>
# N6 C4 m9 b. k4 `& w5 _/ [<P>Recordset only). It is provided only for backward compatibility, and you </P>
$ T, J4 C+ n* ]& F* H9 m& f8 h<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>  u6 d- m9 i; x$ P
<P>using this option. </P>
) e( Q# u  Z0 d- d/ y<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>
" p8 Z! a" a) ^1 n- {3 J9 a<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>( \6 T6 f2 Y  `# i5 v. ]8 S
<P>option, which is provided only for backward compatibility. </P>8 z/ K$ G" h( d2 k
<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>
" F$ o2 C! d" g$ [7 ]7 k" B<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>% |1 m& R- _/ N! T( I: X* J3 w
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>) {! P& e# P- p$ w' _$ x
<P>not opening a Recordset based on a parameter query. For more information, see </P># I2 t! \) M6 d+ }- b/ F
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>
8 `( C2 G& E% J$ n9 Q<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>( s: |! K: |( u
<P>snapshot-type Recordset objects only). </P>
( A) B! h: Q5 ~7 J# ^# X; C<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>0 B+ c4 G: ^2 Y
<P>snapshot-type Recordset objects only). </P>8 M8 m4 I8 l% H( H- t/ X/ d7 v
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>7 Z( z. L% h9 q0 x
<P>and using both causes an error. Supplying a lockedits argument when options </P>1 y3 L) C- W7 N0 h
<P>uses the dbReadOnly constant also causes an error. </P>* |, H5 V5 w+ |& `
<P>  </P>( Z9 g: r2 Q0 T7 ^
<P>You can use the following constants for the lockedits argument. </P># S% P* z' X, Z  }  G$ r6 u2 j' s
<P>  </P>0 u' ^. a( D; {$ M- ]
<P>Constant        Description </P>( |5 i5 `: A; i! v8 J, F& j" f. j
<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>
. n) s6 y9 e+ E6 v% C<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>5 R" F+ U7 R/ ~6 r) e' y' s
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>, Q8 Y6 ?" R( |4 D6 }0 r
<P>run-time error occurs. </P>
7 `& W( g5 W7 |4 L<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>
3 j7 Z( U) v# Z' C; }4 r<P>the Recordset in a multiuser environment. The page containing the record </P>
3 b7 Z, ~, s( ]<P>you're editing is locked as soon as you use the Edit method (default for </P>
9 G, }! Y9 Y* Z/ f/ b5 n+ R<P>Microsoft Jet workspaces). </P>* s! V  x% t& h5 O- C/ D
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>
5 B* H9 F( O0 L7 {- @7 p<P>Recordset in a multiuser environment. The page containing the record is not </P>
* v, d( D* p! y* K& F<P>locked until the Update method is executed. </P>
( G. G2 S# ~, q8 i5 \7 K<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>2 G7 ]5 h( H* a3 r
<P>workspaces only). </P>% H9 \6 k0 d  v
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>7 F2 d& P8 E+ H. X  }' O2 P
<P>only). </P>
9 \# I" V5 S  x5 U! X+ u7 l: B/ K<P>Remarks </P>& @. r/ T( B6 |0 |& F/ C2 I+ y6 Y
<P>  </P>
( M" ]1 X4 q% S) {* Q' ]<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>
/ ]! F3 U$ B/ W* ~4 P7 M& I6 A<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>& ~" K6 D8 x* Q) p) u; f/ S
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>- r2 n- [0 B! n  J6 d2 t! S
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>
& x1 w* u9 ^: R5 M1 \' C<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>* g- H% j+ ], v/ K$ W  s& y+ _3 k$ \
<P>data source, you must first set the Connect property of the linked table's </P>
4 c8 D# p2 Q. j<P>database to a valid ODBC connection string. If you only need to make a single </P>3 @) u0 w8 I- |
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>6 g. D3 H4 o, t
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>* h1 G, `& W) I
<P>argument. </P>
) k  o9 n2 C" h<P>  </P>3 g( y" v: e9 K; C
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>$ i) F: `+ A. K
<P>is of the same type object. If object </P>
* z$ {( u; G, ^0 V<P> refers to a table-type Recordset object, the type of the new object is a </P>" b" I7 B( s8 ]6 g8 r
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>
! ?3 G9 O. e% V" ~. `% u<P>杢ype or ODBCDirect Recordset objects. </P>4 V" f, i( j( H2 ?2 X, |
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>
& |( F4 I& c5 Y' K9 A<P>select query in the source argument, such as </P>
; ~8 U4 M* d  o<P>  </P>* d8 z! F  ]' j! R( ~0 L
<P>"SELECT LastName, FirstName FROM Authors </P>
2 Z3 H" S4 w& M% i  ?<P>WHERE LastName = 'Smith'; </P>1 z9 `: W+ x3 R2 R
<P>SELECT Title, ISBN FROM Titles </P>2 O& j7 h4 G; R
<P>WHERE ISBN Like '1-55615-*'" </P>
; \; t  y( z- S) T1 k# L<P>  </P>6 c5 b! B/ t! n7 Q. I  a
<P>The returned Recordset will open with the results of the first query. To </P>$ q, _, l' M$ q/ J+ W  s( e; Y( e8 `
<P>obtain the result sets of records from subsequent queries, use the </P>
3 e! N6 W5 l1 \) G" h5 J<P>NextRecordset method. </P>
$ h2 G- n" S- G3 u" _: l, ?2 m<P>  </P>
: }9 U2 s7 q6 ?, u: L, h5 i, C. L<P>Note   You can send DAO queries to a variety of different database servers </P>" c& }" z: j3 `  B3 J0 O7 r5 T
<P>with ODBCDirect, and different servers will recognize slightly different </P>
5 m1 X. d0 e+ i! ?<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P># a& }# d5 s, e
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>
: q% @, f( I' B6 A. ^: W<P>included through the Help menu. Be sure to check the appropriate reference </P>9 p7 e5 j- |( [5 P( ?/ |
<P>documentation for the SQL dialect of your database server when using either </P>
& G5 m2 C" D& x# }<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>
% y% [6 W/ a6 @. V1 H/ a5 `<P>client/server applications. </P>
& c. g9 B5 O$ W2 |<P>  </P>% O. R2 s% x9 R5 f" d7 o
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>) C3 J& P. b4 q7 y' N% s/ ]' F
<P>trap changes while two or more users are editing or deleting the same record. </P>, J% p, Z% F) W
<P>For example, if two users start editing the same record, the first user to </P>2 h+ |% @+ k% j; W: J
<P>execute the Update method succeeds. When the second user invokes the Update </P>4 O' S% E/ @/ e& V; S, [; D
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>! y# x1 i1 }" s/ g# a
<P>the Delete method to delete the record, and the first user has already </P>/ W) \3 k4 i: U) g+ @- h
<P>changed it, a run-time error occurs. </P>( U7 D5 _" }* o/ }1 a* Y
<P>  </P>
/ T! Q- m6 y0 v) q<P>Typically, if the user gets this error while updating a record, your code </P>
. m5 m% ?; K9 a- {<P>should refresh the contents of the fields and retrieve the newly modified </P>
2 O( ^" ^1 ]& r2 {, t* _1 |<P>values. If the error occurs while deleting a record, your code could display </P>  g$ c% ~+ s9 {1 |* E6 w9 t5 I: }$ l
<P>the new record data to the user and a message indicating that the data has </P>/ F- W+ I. b5 o' c: x8 P* d
<P>recently changed. At this point, your code can request a confirmation that </P>
3 u4 _+ x* P( T$ A% Z$ Y<P>the user still wants to delete the record. </P>
+ P' ?* R) K" ?" {  Y3 v- q1 K<P>  </P>
0 m7 L4 c# ^( L2 @9 q4 b<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>
: j: \; P, ~) F- Y, x2 ^<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>
) X0 }; t/ p# m7 u+ R2 I& t<P>later) table that has an IDENTITY column, otherwise an error may result. </P># n  p) a* T- A! R, V- X
<P>  </P>% f+ F/ s$ v7 x# O
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>
% C4 e* r" G8 x5 l& h# Q% a<P>the dbRunAsync constant in the options argument. This allows your application </P>
6 j: m" c7 Q5 R* R! H<P>to continue processing other statements while the query runs in the </P>2 H1 C- [  K9 J! c) h5 D
<P>background. But, you cannot access the Recordset data until the query has </P>& l5 h& z8 d  t) N9 X) F  ^
<P>completed. To determine whether the query has finished executing, check the </P>
  y# {5 n2 P: p1 ?1 x<P>StillExecuting property of the new Recordset. If the query takes longer to </P>
8 y' L, {- k' _, {8 \9 V  Y- ~<P>complete than you anticipated, you can terminate execution of the query with </P>
, i6 A1 L. S4 ?( b7 S<P>the Cancel method. </P>2 u9 X) S  E* E9 \; x
<P>  </P>
4 s$ `; N# Y/ o  {<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
' [6 ^+ p  t& E5 C<P>connection is busy with a prior </P>5 X) c" C4 O$ J" C) u3 j
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>
: `1 A( s6 x# l* s$ b$ [, s5 e<P>ODBCDirect, if the server supports this. Another solution is to fully </P>
7 h% b, k* \- N<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>. B2 E% U/ n1 j% y( W
<P>is opened. </P>
, d4 L% \# }4 R" P: e$ n<P>  </P>
8 o7 W6 z3 I! \( ^<P>If you open a Connection object with DefaultCursorDriver set to </P>
7 x- O  \, i+ M0 {, J1 U<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>1 d- @3 D9 e+ W6 D* b5 i& V" S* ~
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>- B5 u9 V2 }2 S+ v, y' s
<P>h in the lockedits argument to enable update caching. See the Update method </P>1 {; E6 `! T4 v) u) R' l* H
<P>topic for details about how to write changes to disk immediately, or to cache </P>8 D$ @6 ]! N* \1 |
<P>changes and write them to disk as a batch. </P>
9 i' e2 y0 r1 }" u- j* v8 O<P>  </P>
/ s8 n0 t, h; ~% e8 Y5 t<P>Closing a Recordset with the Close method automatically deletes it from the </P>5 C8 A9 w+ Q) U+ M( B4 P

9 X5 k) m( V1 T, h" t2 M) o<P>Recordsets collection. </P>1 I$ z; g# n7 {: q9 N, y
<P>  </P>! k7 o2 `1 u. I7 @9 [; n" p
<P>Note   If source refers to an SQL statement composed of a string concatenated </P>/ `  s" L, u. `) Y: l  m4 U6 {
<P>with a non-integer value, and the system parameters specify a non-U.S. </P>: E0 D& q5 B2 L* {+ c+ t
<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>
- d2 _' w7 w: P- j2 p0 f- k<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>5 _( x3 L( [; n$ G# o8 `
<P>Recordset. This is because during concatenation, the number will be converted </P>* }( T% d; T* y: J# D: e
<P>to a string using your system's default decimal character, and SQL only </P>5 i' ^. q9 X/ }9 }* V; s1 y
<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-9 03:44 , Processed in 1.011538 second(s), 52 queries .

回顶部