当前位置: 首页 > 网络学院 > 服务端脚本教程 > ADO > ADO Open 方法

ADO
ADO DataTypes
ADO 摘要
ADO 实例

ADO Open 方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 370 ::
收藏到网摘: n/a

The Open method opens a database element that gives you access to records in a table, the results of a query, or to a saved Recordset.
 Open的作用是:打开一个数据库元素,使你可以访问表格中的数据、查询结果或访问一个已存的记录集。

Tip: Always close the Recordset object after using it, to free system resources. Set the Recordset object to Nothing to completely eliminate it from memory.
提示:当使用这个方法以后,我们通常要关闭记录集对象来释放系统资源。我们可以不对记录集对象设置任何值以使其在内存中不复存在。

Syntax
语法

objRecordset.Open source,actconn,cursortyp,locktyp,opt

Parameter参数 Description描述
source Optional. Specifies a data source.  The source parameter may be one of the following:
可选参数。指定一个数据源。Source[源]参数可以使用下列值:
  • A URL
    一个URL
  • A relative/full file path name
    一个相对/完整的路径名
  • A Command object
    一个指令对象
  • An SQL statement
    一个SQL语句
  • A stored procedure
    一个已存程序
  • A table name
    一个表名称
actconn Optional. A connection string or a Connection object
可选参数。指定一个连接字符串或连接对象
cursortyp Optional. A CursorTypeEnum value that specifies the type of cursor to use when opening a Recordset object. Default is adOpenForwardOnly
可选参数。指定一个CursorTypeEnum值。该值是用于描述打开一个记录集对象时所使用的指针类型的。默认值为adOpenForwardOnly
locktyp Optional. A LockTypeEnum value that specifies the type of locking on a Recordset object. Default is adLockReadOnly
可选参数。指定一个LockTypeEnum值。该值是用于指定一个记录集对象的锁定类型。默认值为adLockReadOnly
opt Optional. Specifies how to evaluate the source parameter if it is not a Command object. Can be one or more CommandTypeEnum or ExecuteOptionEnum values.
可选参数。指定当source[源]参数不是一个指令对象时确定该参数的身份。它可以是一个或多个CommandTypeEnum 或 ExecuteOptionEnum值

Example
案例

Open an ADO Table Recordset:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Customers", conn
%>

Open an ADO SQL Recordset:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
%>


CursorTypeEnum Values

Constant常量 Value值 Description描述
adOpenUnspecified -1 Unspecified type of cursor
不指定指针类型
adOpenForwardOnly 0 Default. A forward-only cursor. This improves performance when you need to make only one pass through a Recordset
仅向前移动指针,默认值。除了只能在记录中向前滚动外,与静态指针相同。当只需要在记录集中单向移动时,使用它可提高性能。(顾名思义,这种指针只能向前移动。然而,由于这种指针功能有限,将它用于系统资源时是非常有效的。)
adOpenKeyset 1 A keyset cursor. Like a dynamic cursor, except that you can't see records that other users add, although records that other users delete are inaccessible from your Recordset. Data changes by other users are still visible.
键集指针。尽管从您的记录集不能访问其他用户删除的记录,但除无法查看其他用户添加的记录外,键集指针与动态指针相似。仍然可以看见其他用户更改的数据。(KeySet指针允许你看见自它创建起其他用户所做的修改,然而你却不能看到其他用户增加或删除的记录。)
adOpenDynamic 2 A dynamic cursor. Additions, changes, and deletions by other users are visible, and all types of movement through the Recordset are allowed
动态指针。可以看见其他用户所作的添加、更改和删除。允许在记录集中进行所有类型的移动,但不包括提供者不支持的书签操作。(此类型的指针功能强大同时也是耗费系统资源最多的指针。Dynamic指针可以看到他们保存记录集合的所有变化。使用Dynamic指针的用户可以看到其他用户所做的编辑、增加、删除。如果数据提供者允许这种类型的指针,那么它是通过每隔一段时间从数据源重取数据来支持这种可视性的。毫无疑问这会需要很多的资源。 )
adOpenStatic 3 A static cursor. A static copy of a set of records that you can use to find data or generate reports. Additions, changes, or deletions by other users are not visible.
动态指针。可以看见其他用户所作的添加、更改和删除。允许在记录集中进行所有类型的移动,但不包括提供者不支持的书签操作。(此类型的指针功能强大同时也是耗费系统资源最多的指针。Dynamic指针可以看到他们保存记录集合的所有变化。使用Dynamic指针的用户可以看到其他用户所做的编辑、增加、删除。如果数据提供者允许这种类型的指针,那么它是通过每隔一段时间从数据源重取数据来支持这种可视性的。毫无疑问这会需要很多的资源。 )


LockTypeEnum Values

Constant常量 Value值 Description描述
adLockUnspecified -1 Unspecified type of lock. Clones inherits lock type from the original Recordset.
不指定锁类型。通过它可以创建一个与原来类型相同的锁
adLockReadOnly 1 Default. Read-only records
默认值,只读。无法更改数据。(这是RecodSet的默认值,如果你把锁定的方式设为该值,那么你将不能更新 Recordset。)
adLockPessimistic 2 Pessimistic locking, record by record. The provider lock records immediately after editing
保守式记录锁定(逐条)。提供者执行必要的操作确保成功编辑记录,通常采用编辑时立即锁定数据源的记录的方式。(如果设置为此类锁定,记录被锁定,且只有在编辑开始到将记录更新的提交给数据提供者这段时间内进行编辑的用户才可以访问! )
adLockOptimistic 3 Optimistic locking, record by record. The provider lock records only when calling update
开放式记录锁定(逐条)。提供者使用开放式锁定,只在调用 Update 方法时锁定记录。(只有在将数据提交给数据提供者的那一瞬间才把记录锁定。)
adLockBatchOptimistic 4 Optimistic batch updates. Required for batch update mode
开放式批更新。用于与立即更新模式相反的批更新模式。(设定为这种类型的锁定制式将被称为批量更新模式的RecordSet。 可以加快更新RecordSet修改数据的速度,但因为同时更新多个记录,它也会恶化与并发访问相关的问题! )


CommandTypeEnum Values

Constant常量 Value值 Description描述
adCmdUnspecified -1 Unspecified type of command
不指定指令类型自变量
adCmdText 1 Evaluates CommandText as a textual definition of a command or stored procedure call
指示提供者应该将Source作为命令的文本定义来计算。
adCmdTable 2 Evaluates CommandText as a table name whose columns are returned by an SQL query
指示ADO生成SQL查询以便从在Source中命名的表中返回所有行
adCmdStoredProc 4 Evaluates CommandText as a stored procedure name
将CommandText作为一个已存的程序名称
adCmdUnknown 8 Default. Unknown type of command
默认值。指定未知的CommandText属性命令
adCmdFile 256 Evaluates CommandText as the file name of a persistently stored Recordset. Used with Recordset.Open or Requery only.
指示应从在Source中命名的文件中恢复保留(保存的)Recordset。它仅能与Recordset.Open 或 Requery 指令一起使用
adCmdTableDirect 512 Evaluates CommandText as a table name whose columns are all returned. Used with Recordset.Open or Requery only. To use the Seek method, the Recordset must be opened with adCmdTableDirect. Cannot be combined with the ExecuteOptionEnum value adAsyncExecute.
指示提供者更改从在 Source 中命名的表中返回所有行/
将CommandText作为一个表的名称(该表的列全部是通过内部的SQL查询语句返回的)。它仅适用Recordset.Open 或 Requery 指令;如果需要使用查找方式,那么Recordset必须以adCmdTableDirect打开。这个值不能与ExecuteOptionEnum值 adAsyncExecute一起使用


ExecuteOptionEnum Values

Constant常量 Value值 Description描述
adOptionUnspecified -1 Unspecified command
指明为指定的指令
adAsyncExecute 16 The command should execute asynchronously. Cannot be combined with the CommandTypeEnum value adCmdTableDirect
指明指令是否需要异步执行。这个值不能与CommandTypeEnum 之中的adCmdTableDirect一起使用
adAsyncFetch 32 The remaining rows after the initial quantity specified in the CacheSize property should be retrieved asynchronously
指明在CacheSize属性中指定了初始量以后,是否应该异步获取保留行[remaining rows]
adAsyncFetchNonBlocking 64 The main thread never blocks while retrieving. If the requested row has not been retrieved, the current row automatically moves to the end of the file. If you open a Recordset from a Stream containing a persistently stored Recordset, adAsyncFetchNonBlocking will not have an effect; the operation will be synchronous and blocking. adAsynchFetchNonBlocking has no effect when the adCmdTableDirect option is used to open the Recordset
指示主要线程在提取期间从未堵塞。如果所请求的行尚未提取,那么当前行将自动移到文件末尾。如果打开的记录流中的记录固定地包含一个记录,那么adAsyncFetchNonBlocking将不会产生作用;才作程序将同时运行以及阻塞该常量。当adCmdTableDirect选项用于打开记录时,adAsynchFetchNonBlocking将不会产生任何作用
adExecuteNoRecords 128 The command text is a command or stored procedure that does not return rows. If any rows are retrieved, they are discarded and not returned. adExecuteNoRecords can only be passed as an optional parameter to the Command or Connection Execute method
它仅指明了指令文本仅是一条不返回任何行的指令或现存程序(如:一条只执行数据插入的指令)。如果没有任何行被提取,那么他们将放弃执行并不返回任何值。
adExecuteNoRecords仅可以作为一个可选参数传递到指令中或连接执行方法[Connection Execute method]中
adExecuteStream 256 The results of a command execution should be returned as a stream. adExecuteStream can only be passed as an optional parameter to the Command Execute method
指明需要以结果流的形式返回命令执行的结果。adExecuteStream仅可以作为一个可选参数传递到指令中或连接执行方法[Connection Execute method]中
adExecuteRecord 512 The CommandText is a command or stored procedure that returns a single row which should be returned as a Record object
指明CommandText仅是返回一个单独行(该单独行作为一条记录对象返回)的一条指令或现存程序

评论 (0) All

登陆 | 还没注册?