QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>
1 G6 O" r7 q7 f  n# d, ^  R! T<>Creates a new Recordset object and appends it to the Recordsets collection. </P>
6 b! e9 Q9 s+ `) a+ Q) T& e# q' ?<>  </P>
6 M* m0 O9 p" E; S4 \6 h5 F: ?( |3 S<>Syntax </P>* ]8 S  w0 L, ]  X. k3 a1 z  l1 Y
<>  </P>
9 e) G# w. s  F. T<>For Connection and Database objects: </P>* V+ q. W$ A8 n4 z
<>  </P>4 i1 @- J- k" C4 t; v
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>( n  P+ A( o# C9 X* R* X" E  K
<>  </P>
. Q+ P& g+ R0 S6 W8 `: Q' H<>For QueryDef, Recordset, and TableDef objects: </P>/ D! I# F, d. N( E
<>  </P>
* H8 J0 S3 C+ t( F: H  i( w<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>7 a6 l& {( n& H8 q. w& |+ x
<>  </P>* E9 u3 ^' q  s+ ]) z- v
<>The OpenRecordset method syntax has these parts. </P>. K$ K! F. ~* ^$ ?
<>  </P>( S* H$ Y9 U) h  G8 A
<>art    Description </P>. t7 E: Y9 s6 u( s3 a9 w% O* @, r
<>recordset       An object variable that represents the Recordset object you wantt to </P>
: i" v! n- ?, v) S0 P7 R- O( O<>open. </P>0 A0 F4 k" E% B+ a+ d' e: e% ^
<>object  An object variable that represents an existing object from which you </P>
$ \* I6 I: X+ J2 g8 q" b<>want to create the new Recordset. </P>* I& o8 @: _/ C+ A
<>source  A String specifying the source of the records for the new Recordset. </P>
* G. d. ~- j+ q* p( k8 I  J. N" D# f<>The source can be a table name, a query name, or an SQL statement that </P>3 K, E; l- g& x5 `0 d5 T$ `, y+ |' j- p
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>0 X: S5 F+ q" W+ q( {/ U
<>the source can only be a table name. </P>
2 t* \+ F+ Z# _& C0 J7 q<>type    Optional. A constant that indicates the type of Recordset to open, as </P>
" k3 t' o% O* x) k/ [5 `6 }<>specified in Settings. </P>9 W3 y' O$ t; r  _5 {' t: c
<>options Optional. A combination of constants that specify characteristics of </P>7 w* y" E( @8 l
<>the new Recordset, as listed in Settings. </P>0 ], r% t) V: t+ W5 g
<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>
. v* y- q* V+ q& v3 j<P>as specified in Settings. </P>0 b; N1 j2 W. q; K1 Z
<P>Settings </P>
! w0 Y! a1 N( F% P5 ]<P>  </P>
* W/ G) X( ~7 r( e- Y. B* }/ \<P>You can use one of the following constants for the type argument. </P>6 r* T/ {7 }- Z% W8 p, f/ c
<P>  </P>
6 p) v  \8 E7 K/ L$ X<P>Constant        Description </P>
* p% m; J' j' E( P, r<P>  </P>
& a4 s4 n7 A4 w, g) \+ z5 Y<P>  </P>4 `2 U! [6 U7 h! j# v8 w) M; ]
<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>7 u! M( ?1 Z8 X- q7 e: b! O; s& C
<P>only). </P>
. {; T' H8 t$ P8 R- z4 R<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>
) D4 x, j; ]# M0 |) a% h3 Q<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>" E, N/ e. ~0 D5 p  o
<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>
1 Z5 K0 Z# N1 v' ^<P>ODBC keyset cursor. </P>
. m! }, F6 y  R' {<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>
7 ?7 z- Q: k  G7 W9 V8 \. V<P>ODBC static cursor. </P>
* t. G% X8 p0 S+ B& y<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>
; g4 k2 Y4 J. t3 a* B8 O6 D<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P># K$ ?6 w+ @0 i, q
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>: P! |0 I- k' I* C2 ?6 E+ G
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>
# s( G8 z  w8 _<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>- B8 B. {; o$ D5 j
<P>y. </P>1 T* p) }0 ^: v. M* }
<P>  </P>
" t$ \( L) b/ a7 n. ^<P>You can use a combination of the following constants for the options </P>9 H4 r" j5 C6 H6 l. _/ q& m
<P>argument. </P>2 D: O0 G8 i. V
<P>  </P>5 G- B, c5 y( A6 j
<P>Constant        Description </P>' N; d- b7 ~6 O$ \
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>
$ f2 O. h; u7 R$ ^% c& N3 f1 S<P>prevents them from editing or deleting existing records (Microsoft Jet </P>
  l% c# v) {0 `2 P3 A2 G; ~* r<P>dynaset-type Recordset only). </P>
. E3 i8 G9 y1 e4 R<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>
$ U/ D) ^; F1 B) i<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>; ~+ i+ E  t4 c2 r) ~5 R9 T' N
<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>5 V1 p8 V& g1 M* {, U+ v7 j
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>
" ~; ], b$ U5 {$ k: ]# a/ }0 M<P>useful in applications where multiple users have simultaneous read/write </P>
4 e9 y  A0 ~( d: r+ m" W9 {7 g<P>access to the same data. </P>9 n/ `" R2 `; K  J5 S
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>
  n5 o/ l" q5 N+ G* `<P>Jet Recordset objects only). </P>; T. h& X4 D% r/ W9 Q
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>9 x" W" m8 {( o6 I! V8 _3 Z
<P>table-type Recordset only). </P>
3 }/ M8 s) m' q# o8 i<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>9 ?* M( I% Q6 S! z
<P>Recordset only). It is provided only for backward compatibility, and you </P># m1 _0 _/ S. \* T5 X
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
8 p. x7 d* Y+ _4 D. M2 I<P>using this option. </P>
- p- p/ W- u) _5 P5 s+ O1 n<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>' ?8 [% g% i7 u, K' r
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>
0 i- c6 c& k2 M9 X5 X$ i<P>option, which is provided only for backward compatibility. </P>
: I: u3 ]4 d$ x2 e% c. U& k<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>
% A2 Q+ l) g- Q5 q<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>0 N4 |% e  p& J) G
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>
- o4 C2 x+ J/ d& x% e+ g- p1 h- y<P>not opening a Recordset based on a parameter query. For more information, see </P>$ A/ k* |# \$ B& Z
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>
! W) Y) T$ [3 b- t" ^<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>/ P8 h8 O/ M% ~: |% C$ a* Q6 B
<P>snapshot-type Recordset objects only). </P>
9 @& `0 j5 \& p% i" Q6 m& r<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>9 p. N5 c. Q' a
<P>snapshot-type Recordset objects only). </P>+ G5 ]* p* Q$ p9 b3 R
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>& ?0 {- L5 G+ U4 [* ~
<P>and using both causes an error. Supplying a lockedits argument when options </P>
, u1 _) X1 G3 F' w' q, z! k<P>uses the dbReadOnly constant also causes an error. </P>
3 M4 f! R0 U8 J: t# `9 g<P>  </P>
: f+ t9 s; w3 N0 W( y<P>You can use the following constants for the lockedits argument. </P>: U5 D1 X1 E6 F% U# I( v
<P>  </P>
# T2 ]) R4 V9 }4 o) f0 U$ t<P>Constant        Description </P>
8 L- h) I( d* @6 i; d% r, X1 q<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>! X/ I% |  b# h' s0 v
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>0 U0 g4 @  C( n2 I: X) F0 Q) d
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>, Z! T6 L) f0 V
<P>run-time error occurs. </P>
6 I% r4 A7 V7 m3 B. U& n<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>, _$ L9 p" a" {( A: T) S, t
<P>the Recordset in a multiuser environment. The page containing the record </P>8 b$ Q! t) M7 F4 D: C( ~
<P>you're editing is locked as soon as you use the Edit method (default for </P>
/ x5 w$ z# d5 f& M7 K<P>Microsoft Jet workspaces). </P>* W, O, R& [( ^6 a8 \- z
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>! g, r2 C; ~4 P5 Y, f4 z
<P>Recordset in a multiuser environment. The page containing the record is not </P>9 S6 }* m0 r, P3 x0 d
<P>locked until the Update method is executed. </P>/ U7 f0 q" O6 t$ c' K* N
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>
# t1 e2 o% |2 Q" n  h) g<P>workspaces only). </P>
0 s& {# O, s% H) s* Z$ E5 Q* M9 Z<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>) P( n4 Z* k* P& q, z( N& e
<P>only). </P>
4 ~; H. c7 w% V" P7 p<P>Remarks </P>
8 h" @3 A: w, x<P>  </P>" x7 v/ ?* a; _0 ^' t
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>
: q8 r) Y! Z' s5 n9 Q<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>
1 _$ B0 D- k: {( a- v. t+ _5 y8 p% [<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>) V/ V! Q4 z4 V
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>
) A0 I% p/ b6 E, k! I4 f9 D# ^<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>+ X7 @/ Z% L+ U! E3 y, u
<P>data source, you must first set the Connect property of the linked table's </P>* B& M5 ]$ k$ ?
<P>database to a valid ODBC connection string. If you only need to make a single </P>% x/ Y; Q9 J* x
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>( ?. B- M4 D+ S- @
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>
% U2 g0 v; P# D6 w4 z<P>argument. </P>) h! W" B. n1 {- e
<P>  </P>
# K8 c, j: e$ Z: D<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>
  K2 B0 d& n' E; z2 g<P>is of the same type object. If object </P>
7 I9 o0 h! K6 t, L<P> refers to a table-type Recordset object, the type of the new object is a </P>
) V7 T  ]4 n) z2 W# R' b0 u& H<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>5 D& g; P1 r2 u( T6 Q) U
<P>杢ype or ODBCDirect Recordset objects. </P>, H; T2 d2 ^: W. _
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>
" N2 t8 {' G* R  ?5 L! x6 g' Q<P>select query in the source argument, such as </P>2 |9 D. l* P2 ]5 e. C+ A
<P>  </P>
5 P- N* B$ f% Y% r5 R' f<P>"SELECT LastName, FirstName FROM Authors </P>* D5 {0 N+ c) e8 b% v
<P>WHERE LastName = 'Smith'; </P>
; G) L# N1 Z; \/ g& V3 F: o/ u<P>SELECT Title, ISBN FROM Titles </P>
4 y' V; y# Q: T, A! u; p: [/ E, I<P>WHERE ISBN Like '1-55615-*'" </P>9 ^' z3 S, y* }! [: z
<P>  </P>8 ?( d* b0 W5 U3 o
<P>The returned Recordset will open with the results of the first query. To </P>
& [/ y. X  ~3 j' p& L( c<P>obtain the result sets of records from subsequent queries, use the </P>
- j; |: Y$ x3 Y0 x$ {1 c<P>NextRecordset method. </P>
5 k/ M& l" B% a  M, N) ^2 d<P>  </P>
  Q8 @- ^8 l0 Q! J# l<P>Note   You can send DAO queries to a variety of different database servers </P>" v* |0 s, e/ V- X( o7 F  ^
<P>with ODBCDirect, and different servers will recognize slightly different </P>
: F9 {% Z6 W9 [4 n% ~/ z4 W% }4 [5 ~<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>+ D# ?3 p7 T  q9 M" S- b
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>3 z# o4 k5 B; r- ~) j
<P>included through the Help menu. Be sure to check the appropriate reference </P># @! _! E: V  X; T$ C
<P>documentation for the SQL dialect of your database server when using either </P>
6 A% L7 ~5 b' s& z+ ~<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>
4 h4 b/ v( c! V5 Y& I<P>client/server applications. </P>
, q( d8 h( o" _+ d2 p<P>  </P>
. c/ C3 ?. l2 H% a<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>9 z+ F( l0 c1 x5 \5 y
<P>trap changes while two or more users are editing or deleting the same record. </P>1 C- [! ~3 Y' T4 z* t
<P>For example, if two users start editing the same record, the first user to </P>
$ h% p+ P( m* C6 T0 _. s<P>execute the Update method succeeds. When the second user invokes the Update </P>% ]+ [6 i& m; o+ W' |
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>
: y" {" u( P$ l0 Q/ ?<P>the Delete method to delete the record, and the first user has already </P>* m/ N5 b6 j; ~8 `
<P>changed it, a run-time error occurs. </P>
0 I* R+ A) h1 R% P6 \1 Z3 C<P>  </P>. w( V2 _+ `0 a  D! E5 \; j1 Z
<P>Typically, if the user gets this error while updating a record, your code </P>- c# ]$ I- R* u; ^  L) {
<P>should refresh the contents of the fields and retrieve the newly modified </P>
4 F1 G' i. x4 x* t( R6 X7 G7 n, B<P>values. If the error occurs while deleting a record, your code could display </P>6 `" f2 z( s: i% S: z
<P>the new record data to the user and a message indicating that the data has </P>! M) |( T: g" [" k3 S3 G
<P>recently changed. At this point, your code can request a confirmation that </P>
  p, [, V& A9 z. K' L5 G# x<P>the user still wants to delete the record. </P>
4 |' q8 V7 x! W<P>  </P>' O' x/ Y) c2 Q
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>
1 M' g. G2 i% q( @# e<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>" X1 N6 f& G& F$ D4 V  W$ o
<P>later) table that has an IDENTITY column, otherwise an error may result. </P>) k, Z9 _! z! n- `; Q2 v- n8 d2 [+ m
<P>  </P>
  v0 O  e! k* _8 @- k1 S<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>
' G2 Q6 K* s0 B. T( a<P>the dbRunAsync constant in the options argument. This allows your application </P>
. L4 A0 `: @, s$ ]+ i" C<P>to continue processing other statements while the query runs in the </P>4 N# i# O# ?5 R7 t) ?
<P>background. But, you cannot access the Recordset data until the query has </P>
% F6 U7 }1 X# H6 k  D& |: {<P>completed. To determine whether the query has finished executing, check the </P>; n  ]: W$ c; J# W
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>( `9 C( v  w, m( a. R5 E3 r1 [6 x
<P>complete than you anticipated, you can terminate execution of the query with </P>$ ?: o2 T: U6 _- n
<P>the Cancel method. </P>, }8 ^+ T; C* r
<P>  </P>, t, N4 r4 o- N9 N) `$ ]
<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
) H' r- Z8 ^' w1 b' C. D% n<P>connection is busy with a prior </P>
% R$ P- S8 H7 M% l9 p: ?0 i<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>3 b: \$ t% P- }
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>6 a; n4 a4 J* P& y! y4 v# C% S8 \; A, H
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>
' @0 ]3 d: n/ K* H3 N2 M<P>is opened. </P>) Q- z$ d  h* w# f! l5 B0 E; O
<P>  </P>
7 I! O- W. x" N# b<P>If you open a Connection object with DefaultCursorDriver set to </P>
6 Y; O* T4 ^$ X8 y8 D: c: t<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>
/ o" |' g( m' M! z<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>' N) G+ o. h: v  s
<P>h in the lockedits argument to enable update caching. See the Update method </P>
; D) b" L6 d) Z- m1 l1 T$ t<P>topic for details about how to write changes to disk immediately, or to cache </P>
- U8 E9 R: x) D" K<P>changes and write them to disk as a batch. </P>
5 d8 N3 i- M; L. S<P>  </P>$ l% N$ O) V9 p6 r: e
<P>Closing a Recordset with the Close method automatically deletes it from the </P>
+ R/ D; F$ @9 t2 z& p- f
! o+ ]  J0 T* _! B: N<P>Recordsets collection. </P>" F4 j- i0 @: r
<P>  </P>
% C1 P/ ]/ U4 N/ |1 u, _2 b<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
: F& I) C! f. o5 `( t$ @/ {) t' h<P>with a non-integer value, and the system parameters specify a non-U.S. </P>
1 i: |- p) ]: ]& n. ~  b- j3 K<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>, |9 P* }7 b0 ~7 |# X  a' b5 Q
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>
2 ?) f/ @9 v) K2 i<P>Recordset. This is because during concatenation, the number will be converted </P>
1 d5 I( P. E! c<P>to a string using your system's default decimal character, and SQL only </P>3 l, }! T5 v# E6 \! @7 I4 X
<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-9 06:55 , Processed in 0.380662 second(s), 52 queries .

回顶部