QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>8 Q# F! R  M1 e0 V4 a# p
<>Creates a new Recordset object and appends it to the Recordsets collection. </P>
( ~  O. D1 j' x( P* `8 S% C# F<>  </P>( e- Y0 N. L2 l8 Z# |7 U# K" u
<>Syntax </P>6 f8 H4 b. L! M6 b4 q  {" b
<>  </P>8 {& F- @5 T4 H% R; _
<>For Connection and Database objects: </P>
+ Z. }% f. n& n! E1 e: f, q<>  </P>, a) F7 H, K0 w' c: t/ t
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>  Z$ }: T) ~- m$ a, w8 r
<>  </P>- l4 [) h% D! d3 A0 p# y6 l$ j
<>For QueryDef, Recordset, and TableDef objects: </P># U8 I5 g) L8 j! P& D
<>  </P>
+ k7 c1 p- Y9 I& M6 S* P<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>* X8 S, L. Z3 [8 E1 U4 Y
<>  </P>8 |$ F3 I3 E: ^
<>The OpenRecordset method syntax has these parts. </P>) K2 Q; X3 Q& k: H+ z+ k+ S
<>  </P>) I7 n/ r& q+ ^2 I* g: w6 h% ?6 x: Z
<>art    Description </P>
$ ^0 W4 ~9 L9 I9 O" _  p<>recordset       An object variable that represents the Recordset object you wantt to </P>! ]* d* a/ b- Z9 C
<>open. </P>
, U) {8 w% \  x8 `4 l$ t' }<>object  An object variable that represents an existing object from which you </P>
+ x, E  V9 {. y<>want to create the new Recordset. </P>
0 o! M. R3 b+ o7 ]4 E! }<>source  A String specifying the source of the records for the new Recordset. </P>2 @. p$ N+ K6 G# D1 [) s
<>The source can be a table name, a query name, or an SQL statement that </P>
1 W; _" ^) A# I1 a: p/ Q/ v5 t" _3 B8 a<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>" C# g8 u$ t9 E! v6 G; G7 d
<>the source can only be a table name. </P>( R3 e( j) a/ \( B
<>type    Optional. A constant that indicates the type of Recordset to open, as </P>9 k# R3 s2 G1 e6 Z3 U
<>specified in Settings. </P>
8 R0 W/ d  G3 ?<>options Optional. A combination of constants that specify characteristics of </P>
, R4 x- t9 U! Q0 _! C<>the new Recordset, as listed in Settings. </P>
+ l0 R& q& w, p& v+ `/ U' x, Y<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>' K, Q) v. r2 a+ u& d) J
<P>as specified in Settings. </P>
' f1 h/ G8 m& X( |<P>Settings </P>$ ~) q. R' K+ o+ m7 F
<P>  </P>8 S/ N4 K" B, b2 }) C
<P>You can use one of the following constants for the type argument. </P>
0 m# j; l1 u/ `' i( \<P>  </P>
3 m' C: X% R* q4 P, _9 c<P>Constant        Description </P>2 K2 n0 }6 K' c6 a' V
<P>  </P>5 C9 s* ^  k& ^5 w& u5 K) E: z
<P>  </P>
; a: Y, R: p) q3 d<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>% A3 z% V% _+ }# V# H, L
<P>only). </P>
9 S7 A8 w( g, K, i2 l<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>5 ?' [& ~# H  G
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>
  e) z. [' r- B( g4 B2 F<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>
0 }7 w7 ]: k5 I' X! M<P>ODBC keyset cursor. </P>
- j$ h4 y" G& M, C( |<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>! h. w3 S0 V% U4 j
<P>ODBC static cursor. </P>
; M( G+ a) }. n( ]0 T5 q" @<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>+ V7 S7 d& Y/ l( h0 N  S% A1 C
<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>, E9 R; E# j2 h0 ]# q0 X: R* y% [# c
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>
  ^  Q& P7 [% ?# u* a* S<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>
. f7 y: p) Q. k) O2 U5 _<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>
; w  O; U& a: a/ ^8 d2 A  }7 R. E<P>y. </P>0 U) V. V/ t- G# i/ C
<P>  </P>
1 T0 g. S) o7 V+ D! f1 w3 I<P>You can use a combination of the following constants for the options </P>5 W. |2 X2 |  _+ ?. F
<P>argument. </P>
6 V+ Y2 J/ X3 O7 K$ I4 v<P>  </P>, v( P3 k0 R# ~* B5 k
<P>Constant        Description </P># {6 h0 Q4 a7 ?4 m
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>! w$ u; ?( }0 @" G& a( b5 C/ M
<P>prevents them from editing or deleting existing records (Microsoft Jet </P>! n! f; R$ `' ~* i2 \* H4 J# x
<P>dynaset-type Recordset only). </P>
$ C6 N7 e% ]$ U$ K) }% L4 v* `<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>
; w. m( U( ^+ p4 F- i<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>  t4 @) C+ X( b9 D
<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>  K" A) R& B+ W8 k
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>; o- }; I4 I$ M" u8 @
<P>useful in applications where multiple users have simultaneous read/write </P>
  C8 B2 Y2 U& P+ W8 L<P>access to the same data. </P>
/ o3 V# q( }; S% I) I/ l3 X! _<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>+ O% _3 ]9 Q: A9 `! J; u+ l
<P>Jet Recordset objects only). </P>- D# ^( V9 V$ v; I
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>
4 C& }4 C/ q2 ^% X3 T<P>table-type Recordset only). </P>5 W3 j# n; C# D. U% U
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>
, l/ Q- h8 B0 h3 Q3 A+ j<P>Recordset only). It is provided only for backward compatibility, and you </P>
2 V# B3 E: F. o, t  B3 T<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>
$ o7 n% ^) y8 a1 {4 E<P>using this option. </P>
3 [2 f7 S7 Q3 w! |+ u<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>
- F5 V/ P& d, O4 f; ~. p7 p3 x<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>% L+ ]2 S( M* J2 K& Z/ T
<P>option, which is provided only for backward compatibility. </P>
# P; X; [3 d1 K1 M; k5 ~' J<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>+ g# J8 `: o9 [5 S4 o, @
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>6 Q! X. e* n. L. q- r
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>" p4 f. X5 s0 h' j4 z6 M
<P>not opening a Recordset based on a parameter query. For more information, see </P>4 X' [0 `- z3 }$ @) A  }
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>! _* u* M+ J) k
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>( i* m2 p7 ^$ `# P% A
<P>snapshot-type Recordset objects only). </P>
" q- K, a9 k3 h/ G<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>( f' R6 e. X: m* X$ I
<P>snapshot-type Recordset objects only). </P>6 P  G" C1 h; l6 h2 n
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>
' }# L) \: e2 [! z; I- R<P>and using both causes an error. Supplying a lockedits argument when options </P>2 }4 i& f# Y) A; M% U! @( l5 W
<P>uses the dbReadOnly constant also causes an error. </P>8 L( z! C2 X5 z, |
<P>  </P>
4 r% E% K+ g3 m' k& u0 d4 M<P>You can use the following constants for the lockedits argument. </P>
9 u) V9 S# t1 L4 j9 l<P>  </P>1 ^# f  m" |% {6 e0 `3 x3 J# x
<P>Constant        Description </P>9 Q. V1 ^! X3 e* L; e
<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>
0 h$ ]  B' \3 i2 p7 f. @; O( ]<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>8 [; v! c) G9 _1 Q. N
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>9 m3 a$ I: b! e5 I4 U$ `8 o
<P>run-time error occurs. </P>
3 J" q" L7 T% |<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>
  |  t6 v7 K' E+ }<P>the Recordset in a multiuser environment. The page containing the record </P>* T; _7 F# b$ S* V! e
<P>you're editing is locked as soon as you use the Edit method (default for </P>4 d0 D3 ~, ?/ @& p
<P>Microsoft Jet workspaces). </P>
, V# E, a* m9 t3 q4 L( `) c<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>1 k! Z6 d0 C1 v, w  H/ ^5 W
<P>Recordset in a multiuser environment. The page containing the record is not </P>
8 s% ?. e; i9 D  y% P- w<P>locked until the Update method is executed. </P>0 I* I  z9 P, L- l) n
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>
- e3 r6 k2 Z; C" [% N8 {# s<P>workspaces only). </P>
+ b9 e2 r$ n6 f- R4 a/ u% O<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P># J% C' t1 F: W% Z# F8 s
<P>only). </P>0 z. {3 P* H% s- K1 y: L
<P>Remarks </P>' ]3 C: ~4 \5 Q8 x, v" T
<P>  </P>
% w& B3 }9 n0 L+ X9 {<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>
# W7 V* n" \0 |. [<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>3 s6 |1 ?7 B3 B' p4 W
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>
; k# D0 Y' |! j( f, u<P>the type argument; if you do, a run-time error occurs. If you want to use an </P># q1 [( E  c2 p  n4 a# N# M
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>
2 k# ]) b! i# U! j3 C+ r<P>data source, you must first set the Connect property of the linked table's </P>/ v* @! O8 y6 U- Z+ s
<P>database to a valid ODBC connection string. If you only need to make a single </P>: d+ A2 d  N3 i! o: C
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>* A2 `7 l# A: k- E* q. o
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>
* l' p- i! Q6 @<P>argument. </P>! ?) Z9 t) X$ d6 _4 B0 T( T
<P>  </P>
$ T6 L* y- `1 N. w<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>: R! T0 s: c" i% A$ ]
<P>is of the same type object. If object </P>
+ J" Z6 E' Q  _+ W9 x2 l. j<P> refers to a table-type Recordset object, the type of the new object is a </P>+ K, S& ~, Z. i7 u. C6 b
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>" R9 B4 V" @/ z9 j2 |
<P>杢ype or ODBCDirect Recordset objects. </P># i6 R4 M# ]$ ?9 n1 r' {
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>$ g- |# k% z8 j( ^* }5 v
<P>select query in the source argument, such as </P>
5 c4 j2 f" r$ e, t' s+ ^<P>  </P>% V6 a' |% N( ?
<P>"SELECT LastName, FirstName FROM Authors </P>
) a6 G7 F8 w; l2 g1 E8 f! ~<P>WHERE LastName = 'Smith'; </P>, F) E# n' u" _: K, r/ g9 z: b
<P>SELECT Title, ISBN FROM Titles </P>
4 H, R3 E& o- q. ^$ |# B! V1 D<P>WHERE ISBN Like '1-55615-*'" </P>! ^# v  m& Z+ f* s) l& N- {
<P>  </P>
% m9 }9 Y" U, A: G) e8 F<P>The returned Recordset will open with the results of the first query. To </P>
2 p7 n5 d0 l* g<P>obtain the result sets of records from subsequent queries, use the </P>
3 g& ]+ m, o8 q. n2 n0 {<P>NextRecordset method. </P>( s5 K. s- A4 L# ^# S" M
<P>  </P>; j2 X& g( E1 `1 k: ?; w4 Y/ t, Z
<P>Note   You can send DAO queries to a variety of different database servers </P>
9 W6 S/ O3 S) i, }7 D<P>with ODBCDirect, and different servers will recognize slightly different </P>
  E$ R7 Z# R- P( V/ Q8 Q$ w<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>
! K2 l: U3 Y7 m! l# R! r<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>
, m( I- `; L6 _; F- `( U  p7 S<P>included through the Help menu. Be sure to check the appropriate reference </P>8 k% a( h" v* F* w6 R
<P>documentation for the SQL dialect of your database server when using either </P>! }  D3 K% c2 O  \0 ~% P5 S
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>' I' \0 c1 H) n1 w8 i: F
<P>client/server applications. </P>
; k8 H( N8 b/ k8 H: z<P>  </P>
/ ?( a' N: C6 l' x<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>, c1 _7 p4 D% L( q) ~! b+ \0 l2 ]
<P>trap changes while two or more users are editing or deleting the same record. </P>
' U5 X% N( J/ q" m! B0 v<P>For example, if two users start editing the same record, the first user to </P>
/ U( Q- D& F6 e. A# V3 l" S1 G# c1 n3 G<P>execute the Update method succeeds. When the second user invokes the Update </P>
. _# z0 l0 m" F/ [2 }<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>
5 J) H% C6 h, S<P>the Delete method to delete the record, and the first user has already </P>7 @0 u4 u: U  F. r( H  z7 o4 y
<P>changed it, a run-time error occurs. </P>( f1 @5 O7 _" Y6 Y, z7 O, W, T
<P>  </P>9 w2 v7 R; e" i) M3 N2 g: z2 p
<P>Typically, if the user gets this error while updating a record, your code </P>. A4 ~5 e8 Z' ?) n
<P>should refresh the contents of the fields and retrieve the newly modified </P>8 j: K" I* c; f
<P>values. If the error occurs while deleting a record, your code could display </P>
- d/ f. H3 |7 A<P>the new record data to the user and a message indicating that the data has </P>3 u1 s' l( P$ s, g
<P>recently changed. At this point, your code can request a confirmation that </P>$ ?' j: _1 W9 j: b/ v
<P>the user still wants to delete the record. </P>9 j, P- Y& X, k+ k7 s9 u. y9 [
<P>  </P>
' T7 J' ]! a1 Y+ ]: u<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>4 w4 E3 M& U3 P
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>
9 Y$ R' d  j; N# A/ j  t<P>later) table that has an IDENTITY column, otherwise an error may result. </P>
! G; K- n+ q3 x' g<P>  </P>  ^( W$ X+ u! S5 L0 O
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>1 U" e# V( Q- ?$ v
<P>the dbRunAsync constant in the options argument. This allows your application </P>
3 m) E& ?" k( ?' u$ Z<P>to continue processing other statements while the query runs in the </P>
8 O; F" a& ?/ G* r7 a! w<P>background. But, you cannot access the Recordset data until the query has </P>
8 L. N5 j) x$ P3 J. W5 H<P>completed. To determine whether the query has finished executing, check the </P>6 D6 s7 Q- O4 N& R  n9 h3 n' V
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>
' i( h4 H  u) }% @<P>complete than you anticipated, you can terminate execution of the query with </P>
0 @2 C4 x) n* f4 p- l. G" V! C% P9 [<P>the Cancel method. </P>  `7 D( s3 f, F; e  o7 W8 e" v: q
<P>  </P>
$ ^2 e- q' G- ?5 F6 ?+ j$ r; w<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
# @# P; T2 A1 j9 R8 J5 s3 ~<P>connection is busy with a prior </P>) G: d* E8 z3 T& w6 W
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>- I$ v9 o# z# S8 j' {
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>- n8 P4 _. ~) z7 Z. n  A& b
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>
: F" ^6 E7 X; N) S9 u! i  x<P>is opened. </P># \+ P/ g: O5 A5 M' V
<P>  </P>
5 M' o) |% V. B( A! q2 E, v& G<P>If you open a Connection object with DefaultCursorDriver set to </P>
( ?: _$ x4 d4 f: ^<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>3 P3 t' \% [* v+ R4 f. V0 L
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>
9 l+ [! {! v7 V2 l1 S3 |' N<P>h in the lockedits argument to enable update caching. See the Update method </P>) i. e' s! U: w+ n* t
<P>topic for details about how to write changes to disk immediately, or to cache </P>) I5 o, r$ _) Z4 w* O0 Z
<P>changes and write them to disk as a batch. </P>) W% o9 @( m* w: k
<P>  </P>
2 e+ `3 r4 W$ N- @$ ]<P>Closing a Recordset with the Close method automatically deletes it from the </P>
( a3 n8 ]* R8 i' P5 y% z4 c" Y  K3 k9 {7 J/ W
<P>Recordsets collection. </P>
0 s- K+ }# I( o* T3 w<P>  </P>
/ r9 D1 e# A2 e$ ?% L( W<P>Note   If source refers to an SQL statement composed of a string concatenated </P>  e3 h% @2 R! E& w& @( Q
<P>with a non-integer value, and the system parameters specify a non-U.S. </P>
5 ]5 {8 f6 {8 @9 @( |<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>, ]9 H4 a$ E- H; {
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>
2 R; ?3 y3 k7 y" G3 ?5 g! Q, }- a<P>Recordset. This is because during concatenation, the number will be converted </P>
6 a4 O2 ^! M, |+ s9 D<P>to a string using your system's default decimal character, and SQL only </P># z2 p, p4 z- ^% T4 J
<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-13 02:03 , Processed in 0.422046 second(s), 51 queries .

回顶部