QQ登录

只需要一步,快速开始

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

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

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2005-1-26 12:38 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<>  </P>6 s/ P& m2 ~; c( z
<>Creates a new Recordset object and appends it to the Recordsets collection. </P>0 [3 e+ t$ K& K2 A+ ^8 d
<>  </P>0 X2 A: X+ p/ i- o2 R
<>Syntax </P>
/ y+ `5 F" d1 U8 @7 W/ i; z<>  </P>
9 k3 d" |* Q/ F! L) c7 W<>For Connection and Database objects: </P>
1 ^8 M. H' S! u9 Q2 @<>  </P>
% l/ K8 l+ }7 H7 S<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>
4 q% W. Z# b& `! [* K% o<>  </P>6 W( S% C* I: |* y
<>For QueryDef, Recordset, and TableDef objects: </P>+ K. n# D- U% i( G4 L( {, w
<>  </P>
" E/ v) `; {% d6 O/ N<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>
) v- r9 v0 P9 L9 U# q# I/ M<>  </P>
. h% A: k2 r, q<>The OpenRecordset method syntax has these parts. </P>
/ j* _3 W( P" F1 E" D<>  </P>
% M( m* t' X1 q' B9 [; J<>art    Description </P>
! ^% D3 a$ M) J; j+ d6 Q2 ?<>recordset       An object variable that represents the Recordset object you wantt to </P>8 I4 C% Q4 a( w% Y
<>open. </P>
! U5 ?" U% I) b( @' y<>object  An object variable that represents an existing object from which you </P>1 w5 g; S! }8 }  R$ V- L2 l  F: U
<>want to create the new Recordset. </P>
" O+ M! B2 p) ^7 E<>source  A String specifying the source of the records for the new Recordset. </P>
6 z% x( N/ r) S8 ~. @<>The source can be a table name, a query name, or an SQL statement that </P>
, B$ h; X# c5 T$ i; i' g. M8 s<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>
. w5 b# ^9 }" B# M2 ]<>the source can only be a table name. </P>
: h' U6 K$ F/ _! z) R- G! f6 L! Y<>type    Optional. A constant that indicates the type of Recordset to open, as </P>
: g6 _. v1 i) v# |<>specified in Settings. </P>. r2 j$ s3 m+ I6 q
<>options Optional. A combination of constants that specify characteristics of </P>
& v$ b, s% S7 I* s5 o0 O<>the new Recordset, as listed in Settings. </P>
5 k+ \6 N! h3 \! e2 f9 O<>lockedits       Optional. A constant that determines the locking for the Recordsset, </P>, X3 C! q2 Y/ R3 j& c
<P>as specified in Settings. </P>
" T1 s+ X7 l+ B7 {% Q6 g<P>Settings </P>( }+ Z0 Q5 m: a' R3 P( `( T- Z
<P>  </P>
4 U4 x3 x# u& A7 w8 \" s. |<P>You can use one of the following constants for the type argument. </P>
8 P, F- }/ @1 L<P>  </P>( q' j, e% T  [) p/ F! ]
<P>Constant        Description </P>4 p4 _- x4 m+ ^& [- p! k$ Q3 P" e
<P>  </P>4 v4 q) e$ F1 d- `2 b5 l5 n& l, @
<P>  </P>
& Y/ |5 l# [# L+ R4 X$ a) W5 j<P>dbOpenTable     Opens a table-type Recordset object (Microsoft Jet workspaces </P>
& Z$ y6 j* k0 x$ w+ ~: @" i# l2 d, n<P>only). </P>" K- _. m6 G: }0 D1 u
<P>dbOpenDynamic   Opens a dynamic-type Recordset object, which is similar to an </P>, e8 {  M$ m0 N& R2 E; f+ {
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>2 Z9 {9 R5 r' I) H
<P>dbOpenDynaset   Opens a dynaset-type Recordset object, which is similar to an </P>
/ G/ Y( J1 N3 E3 o<P>ODBC keyset cursor. </P>3 d7 A0 y3 E1 u( A
<P>dbOpenSnapshot  Opens a snapshot-type Recordset object, which is similar to an </P>3 {9 v. |* f8 l
<P>ODBC static cursor. </P>8 G7 D, x/ @4 r& J
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>
& ], V8 y5 ]# P6 F4 ~" [<P>Note   If you open a Recordset in a Microsoft Jet workspace and you don't </P>
3 ^5 U- {7 r4 d) ?3 y% D; M<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>- F' ^8 o! W7 `$ |5 a" C. N7 e
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>2 z8 D1 I) ?: P0 Y
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>
& i  Q1 o8 j: r4 n. P+ ~/ A0 h6 H; ~$ D<P>y. </P>
/ `" O! x- O- A' w. e1 n<P>  </P>
6 t; F* z$ I3 [, j$ C; |2 W<P>You can use a combination of the following constants for the options </P>
# e0 F* }6 ]( h4 m; \<P>argument. </P>
4 E( B9 I- a9 p' B  o! d<P>  </P>
$ I) l. X& f! \, @  X2 F+ c8 S; Q+ l<P>Constant        Description </P>" R/ E" L6 v+ S- ~& [2 D
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>
: d) j5 y2 B9 N0 ~9 `<P>prevents them from editing or deleting existing records (Microsoft Jet </P>
* z, }' z% J' ?% m" h<P>dynaset-type Recordset only). </P>
" I; |' X- R. Y3 M( @<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>
' A( z* H* Y6 I* D<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>- p+ x/ u" K! V" ?% t0 I% n
<P>dbSeeChanges    Generates a run-time error if one user is changing data that </P>5 J) Y1 V+ L# V- z8 H
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>
6 U* C2 |/ G) N6 {8 l<P>useful in applications where multiple users have simultaneous read/write </P>
  K& ~& k5 X- U1 P. {) ?* X<P>access to the same data. </P>
' z6 ]% F  e8 P+ S0 M<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>7 m  F& i) |- \$ Y5 ?- b2 V! U
<P>Jet Recordset objects only). </P>
- G) _1 u/ H/ z, r* U2 {) t<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>0 Z+ l2 b6 @; V0 r7 R
<P>table-type Recordset only). </P>
1 [2 D! f0 }9 ?. W: a3 o<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>, Z. h2 r* a, A3 T' O% {4 |  [
<P>Recordset only). It is provided only for backward compatibility, and you </P>2 j2 D$ o# P' x
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>! u! v9 A2 G1 g( x4 S% U& C
<P>using this option. </P>$ |: A! Q. `/ W+ S
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>
7 W$ G5 q/ o( V<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>& u+ n$ P+ }  I# w, h$ G3 X& s5 w
<P>option, which is provided only for backward compatibility. </P>
& w3 B/ y* Q" J$ O3 b/ f<P>dbRunAsync      Runs an asynchronous query (ODBCDirect workspaces only). </P>
. O* I9 k9 H* L' K' @. t<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>
  y: L$ h7 G& g2 a<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>
8 v9 R' s* ^, `  \9 }# c<P>not opening a Recordset based on a parameter query. For more information, see </P>
2 D" J0 j+ a8 v/ q3 B2 K- g8 K. t<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>% [8 i: U7 q( b9 C2 W
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>
8 u: N3 B% U% p1 ~6 q( d<P>snapshot-type Recordset objects only). </P>; A  L- E& ]' m2 I4 M6 a" n+ m
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>
+ n" n% \; j0 O, u0 ^<P>snapshot-type Recordset objects only). </P>  f  i" Y. t& o1 X+ s& V. e
<P>Note   The constants dbConsistent and dbInconsistent are mutually exclusive, </P>
; ?/ a' G$ R7 l" k1 z% ~! s<P>and using both causes an error. Supplying a lockedits argument when options </P>
: }' b0 ~7 q, ?* h( ~0 z5 ~% u<P>uses the dbReadOnly constant also causes an error. </P>
, ?9 U! @$ F1 B2 e<P>  </P>8 ?, p7 `. s, `3 {' B
<P>You can use the following constants for the lockedits argument. </P>$ W( [6 c; @+ y7 j
<P>  </P>
1 V% b0 P* z/ S/ [- [<P>Constant        Description </P>
1 Z, i1 J) p9 j( {% F) K1 y) C<P>dbReadOnly      Prevents users from making changes to the Recordset (default for </P>+ g9 {# [5 X  k! J  U' q/ S
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>
9 k5 ?9 ~+ t% O<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>5 X" Y" o7 N; o4 G9 i7 g/ g
<P>run-time error occurs. </P>3 L; e3 }3 z; J5 j3 g8 P& j( _/ g
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>/ r; r) d/ f& W
<P>the Recordset in a multiuser environment. The page containing the record </P>8 y2 {5 [0 ^5 g' e: L
<P>you're editing is locked as soon as you use the Edit method (default for </P>
7 b6 Y$ O/ p: {$ K) w! n/ T- J# S' s<P>Microsoft Jet workspaces). </P>; B2 F9 Z; y7 i8 s, S; _$ n
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>  w/ z2 p" ], _7 l8 V
<P>Recordset in a multiuser environment. The page containing the record is not </P>
7 S0 m% \3 c7 v1 ^, ^1 M<P>locked until the Update method is executed. </P>. P7 [) K9 A% Q
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>
: y2 W' @; a0 B) M& S<P>workspaces only). </P>
: @) D* v% R7 X7 r& ^! Z+ F$ Q<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>
0 L/ s3 P' s9 H7 _# k% F, W; D+ g<P>only). </P>
+ Q" i0 W( ~( U6 j<P>Remarks </P>0 E6 @# {% M1 {& G3 q" K! k0 R5 f
<P>  </P>
8 O) q; O& |8 d9 |1 Q<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P># i0 n3 A# ?/ G
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>) _6 l! m: z% c& s; z1 k/ ]
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>, S: L- ]9 Z" U, d. z
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>. q' K- S, A9 I
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>
4 j  ~& F9 P8 M1 O5 R, N<P>data source, you must first set the Connect property of the linked table's </P>
8 c$ a; I! l* L4 o' q2 m<P>database to a valid ODBC connection string. If you only need to make a single </P>8 T5 M- _( R" F: U8 S
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>: D- {1 q% V# u3 b
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>6 l. T. D9 M( m& d
<P>argument. </P>
2 |1 o9 N. K5 m+ x3 {- r<P>  </P>. b" V$ v) {( d
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>8 h9 k% T4 Y% b9 ?
<P>is of the same type object. If object </P>
3 K8 `) \5 R. R: K4 h, S* j<P> refers to a table-type Recordset object, the type of the new object is a </P>
3 y1 w+ Z1 ~) d  `5 P) [  W<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>
) G3 [2 Q1 P* R<P>杢ype or ODBCDirect Recordset objects. </P>
/ E" w% |& `9 `- F2 s<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>
: g+ _# \1 T- H% k. `( e<P>select query in the source argument, such as </P>8 w) ]+ d9 K# m
<P>  </P>
( V$ e! ?/ M& S" z1 a+ ?. B<P>"SELECT LastName, FirstName FROM Authors </P>% q2 ]8 C4 R' b# y+ s  V9 n
<P>WHERE LastName = 'Smith'; </P>
) F( d5 A/ m% l7 o<P>SELECT Title, ISBN FROM Titles </P>2 s+ _5 }, q: Z, X# r$ }* Y; `) ]
<P>WHERE ISBN Like '1-55615-*'" </P>
* u, D8 P2 d# [' k0 Y0 [! M, ], e0 P<P>  </P>
+ Q) X; b4 J( b( s% Z, B4 `<P>The returned Recordset will open with the results of the first query. To </P>
/ h+ Q5 G# A3 I3 b% x% |<P>obtain the result sets of records from subsequent queries, use the </P>
! x% s2 |; g* p" _. h3 Z7 B<P>NextRecordset method. </P># B  a. J) @% t7 r' G/ R6 S" }) R$ q
<P>  </P>0 i: s/ z. i! C0 ^, G% S* U  m  K8 ~5 M
<P>Note   You can send DAO queries to a variety of different database servers </P>
4 ]7 R1 A6 {- {0 i0 t" i$ W$ |% L<P>with ODBCDirect, and different servers will recognize slightly different </P>) p7 Q/ y6 N6 f, v( Z
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>
9 ?" ~* b5 w# N6 C: ]4 T, U<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>
8 H8 ]9 K" y. R  O( X$ f0 Z<P>included through the Help menu. Be sure to check the appropriate reference </P>
3 H9 K& @( ^* v( r# D4 |( o/ x<P>documentation for the SQL dialect of your database server when using either </P>( B0 m- u- `9 P$ [3 j& I- V9 _
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>% e6 H$ |, k% Y. ]# w0 a2 D6 u
<P>client/server applications. </P>
& C/ K9 t# Q: y, U" O<P>  </P>
1 r6 n- ~5 k" [' x6 A* m<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>5 o' v* y% p+ j) D: w
<P>trap changes while two or more users are editing or deleting the same record. </P>
! j3 P8 x: a4 v2 P5 B<P>For example, if two users start editing the same record, the first user to </P>& z3 r. G8 v& s* p
<P>execute the Update method succeeds. When the second user invokes the Update </P>
) j$ M4 a1 U$ m) A; w9 G<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>
- K" n4 U' z- X$ s% q$ _% @5 @<P>the Delete method to delete the record, and the first user has already </P>
( J, \: t9 W8 d: A<P>changed it, a run-time error occurs. </P>
) V! Y( y: P6 b& S% B  f<P>  </P>
# V% G2 ~: n( M) L# B; G<P>Typically, if the user gets this error while updating a record, your code </P>
5 F, a, r' i3 _5 L" N" L$ I<P>should refresh the contents of the fields and retrieve the newly modified </P>) Z4 i3 b8 I/ ?, g' [
<P>values. If the error occurs while deleting a record, your code could display </P>6 i: b  K. p, k' z& {
<P>the new record data to the user and a message indicating that the data has </P>6 c* H3 J/ P3 n1 q" w  V' |
<P>recently changed. At this point, your code can request a confirmation that </P>
. B; Q. d- z% n4 ^( w! _  R<P>the user still wants to delete the record. </P>
* ]6 a. w; h: W+ L( B- C<P>  </P>6 `& p( P% x! V% ^* n
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>
$ r+ Y- p$ v: a9 N4 b6 c& C<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>, ?' _+ Y4 D- l, W3 r
<P>later) table that has an IDENTITY column, otherwise an error may result. </P># v7 z, D* U) q: K: Q7 K
<P>  </P>
$ v3 p" d' t; @<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>2 v% ?4 E5 U' p7 x  e
<P>the dbRunAsync constant in the options argument. This allows your application </P>
: [. W1 p! \5 X( E. P& [<P>to continue processing other statements while the query runs in the </P>
6 O# i& _# ~/ w( a: h- j<P>background. But, you cannot access the Recordset data until the query has </P>
2 i0 N; Q9 e( I; h<P>completed. To determine whether the query has finished executing, check the </P>0 i. M! ?" n5 V2 H- [
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>0 m9 ~( _  r/ s/ E) Y1 I7 Z
<P>complete than you anticipated, you can terminate execution of the query with </P>' a6 ~" K% ?0 e( n* V
<P>the Cancel method. </P>
3 ^, a2 W! b- N<P>  </P>% W! S& K( G0 H. ~" {2 }  Z
<P>Opening more than one Recordset on an ODBC data source may fail because the </P>
0 M6 ]  ~# R1 {' F. F: N6 U<P>connection is busy with a prior </P>
( V6 l: J# @$ |<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>  A( i5 L( X1 Z8 \" s
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>
7 b7 j: k$ p/ b  W: C<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>% c. O* M: ?4 c$ r4 y  w; H$ ~- O
<P>is opened. </P>* v& \* K% C/ E3 z- V, z4 G- ?
<P>  </P>
. f7 I' g. ~/ k, p. v; N7 w<P>If you open a Connection object with DefaultCursorDriver set to </P>
+ y6 t* }1 `, J  O<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>% }$ O1 c' }$ r+ b
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>
; ]9 U1 V* P# {, {, }<P>h in the lockedits argument to enable update caching. See the Update method </P>9 u# I: C+ c, J: e
<P>topic for details about how to write changes to disk immediately, or to cache </P>
. d% S; [# d2 q2 K<P>changes and write them to disk as a batch. </P>6 m, L/ {( S! F0 d4 C# v
<P>  </P>1 @' {8 }: H% @  D. _. z
<P>Closing a Recordset with the Close method automatically deletes it from the </P>
8 Z8 m' c' o' |- T5 O7 c7 i3 S% ]' V
1 x! L, s/ i' e; G; t/ Q<P>Recordsets collection. </P>0 k+ t6 B5 o/ O; S" b* g
<P>  </P>  c7 Z' e# @3 S3 c+ o3 j& i
<P>Note   If source refers to an SQL statement composed of a string concatenated </P>
6 |3 Y$ ~' J0 y$ W& o8 Z<P>with a non-integer value, and the system parameters specify a non-U.S. </P>) Q, t' R! f4 d# x6 J) D
<P>decimal character such as a comma (for example, strSQL = "PRICE &gt; " &amp; </P>0 }' L4 A2 c  m" X. ?( O
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>
6 ?& B/ Q  W" _- |* @0 G! J! c4 B<P>Recordset. This is because during concatenation, the number will be converted </P>
$ x. r, c# P0 C0 `<P>to a string using your system's default decimal character, and SQL only </P>, K7 H( ~+ y. u6 M- i0 \; ?
<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-11 09:11 , Processed in 0.273898 second(s), 52 queries .

回顶部