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

ADO
ADO DataTypes
ADO 摘要
ADO 实例

ADO Recordset


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

Examples
案例

GetRows
This example demonstrates how to use the GetRows method.
GetRows
这个案例告诉我们如何使用GetRows方法。


Recordset Object
Recordset[记录集]对象

The ADO Recordset object is used to hold a set of records from a database table. A Recordset object consist of records and columns (fields).
ADO Recordset对象的作用是:保留一组数据库表的记录。一个Recordset对象是有记录(行)和字段(列)组成的。

In ADO, this object is the most important and the one used most often to manipulate data from a database.
在ADO中,对象是最重要的,我们会经常通过它对数据库中的数据进行操作。

ProgID

set objRecordset=Server.CreateObject("ADODB.recordset")

When you first open a Recordset, the current record pointer will point to the first record and the BOF and EOF properties are False. If there are no records, the BOF and EOF property are True.
当你第一次打开一个记录集时,当前的记录指针将指向第一条记录,此时,BOF和EOF属性值都为False[逻辑假];如果不存在记录,那么BOF和EOF属性值都为True[逻辑真]。

Recordset objects can support two types of updating: 
Recordset[记录集]对象支持两种类型的更新:

  • Immediate updating - all changes are written immediately to the database once you call the Update method.
    直接更新 – 一旦你请求Update方法时,所有的改变都将被直接写入数据库
  • Batch updating - the provider will cache multiple changes and then send them to the database with the UpdateBatch method.
    批量更新 – 技术提供对象[provider]将首先对所有的改变进行缓存,然后再通过UpdateBatch方法将它们集体发送到数据库完成更新。

In ADO there are 4 different cursor types defined:
在ADO中,一共定义了4种不同类型的指针:

  • Dynamic cursor - Allows you to see additions, changes, and deletions by other users.
    动态指针 – 允许你查看添加及变更信息,同时允许其他用户删除信息
  • Keyset cursor - Like a dynamic cursor, except that you cannot see additions by other users, and it prevents access to records that other users have deleted. Data changes by other users will still be visible.
    键盘指针 – 该指针与同动态指针类似,唯一的不同就是:你不能查看其他用户添加的信息,并且,它不允许你访问已被其他用户已经删除的信息。其他用户改变后的信息仍然是可见的
  • Static cursor - Provides a static copy of a recordset for you to use to find data or generate reports. Additions, changes, or deletions by other users will not be visible. This is the only type of cursor allowed when you open a client-side Recordset object.
    静态指针 – 它提供了一个记录集的静态复版,通过它可以查找数据或生成报告。其他用户对信息的添加、更改和删除都是不可见的。该类型的指针指允许你打开客户端记录集对象
  • Forward-only cursor - Allows you to only scroll forward through the Recordset. Additions, changes, or deletions by other users will not be visible. 
    前置指针 – 指允许你向前翻滚滚动条查询信息。其他用户对信息的添加、更改和删除都是不可见的。

The cursor type can be set by the CursorType property or by the CursorType parameter in the Open method.
指针类型可以通过Open方法中的CursorType属性或CursorType参数进行设置。

Note: Not all providers support all methods or properties of the Recordset object.
注意:并不是所有的技术提供对象都支持Recordset[记录集]对象中的所有方法或属性。


Properties
属性

Property属性 Description描述
AbsolutePage Sets or returns a value that specifies the page number in the Recordset object
设置或返回一个用于指定记录集对象中具体页数的长值
AbsolutePosition Sets or returns a value that specifies the ordinal position of the current record in the Recordset object
设置或返回当前记录指针在记录集中具体位置的一个序数
ActiveCommand Returns the Command object associated with the Recordset
返回一个通过Command[指令]对象创建的Recordset[记录集]对象
ActiveConnection Sets or returns a definition for a connection if the connection is closed, or the current Connection object if the connection is open
设置或返回一个通过Command[指令]对象创建的Recordset[记录集]对象
BOF Returns true if the current record position is before the first record, otherwise false
如果当前记录指针位于记录集中的第一条记录之前,则返回True(-1);否则返回False(0)
Bookmark Sets or returns a bookmark. The bookmark saves the position of the current record
制定一个书签。该书签将保存当前记录的指针位置
CacheSize Sets or returns the number of records that can be cached
指定允许在本地内存中进行缓存的记录数量。其值必须大于0
CursorLocation Sets or returns the location of the cursor service
设置或返回指针的位置
CursorType Sets or returns the cursor type of a Recordset object
设置或返回了用于打开一个记录集对象的指针类型
DataMember Sets or returns the name of the data member that will be retrieved from the object referenced by the DataSource property
设置或返回一个字符串值,该值包含了从对象(该对象是通过DataSource属性返回的)中获取的数据成员名称
DataSource Specifies an object containing data to be represented as a Recordset object
指定一个包含数据的对象,以作为一个Record[记录集]对象的
EditMode Returns the editing status of the current record
返回一个EditModeEnum值,用于指定当前记录的编辑状态
EOF Returns true if the current record position is after the last record, otherwise false
如果当前记录指针位于记录集中的最后一条记录之后,则返回True(-1);否则返回False(0)
Filter Sets or returns a filter for the data in a Recordset object
用于筛选记录对象中的数据的过滤器
Index Sets or returns the name of the current index for a Recordset object
设置或返回当前记录集对象索引的名称
LockType Sets or returns a value that specifies the type of locking when editing a record in a Recordset
设置或返回一个在编辑记录集中的记录时,指定锁的类型的值
MarshalOptions Sets or returns a value that specifies which records are to be returned to the server
设置或返回一个用于指定需要被传回服务器的记录的值
MaxRecords Sets or returns the maximum number of records to return to a Recordset object from a query
设置或返回一个长值,它是用于指定返回到记录集对象中的最大记录数(该记录位于查询语句中)
PageCount Returns the number of pages with data in a Recordset object
返回一个用于指定记录集对象中数据页面数量的值
PageSize Sets or returns the maximum number of records allowed on a single page of a Recordset object
设置或返回了一个长值,它是用于指定从记录集对象的一页中上允许返回的最大记录数
RecordCount Returns the number of records in a Recordset object
返回一个长值,用于指定记录对象中的记录数量
Sort Sets or returns the field names in the Recordset to sort on
设置或返回一个字符串值,用于指定记录集中需要进行排列的字段名称
Source Sets a string value or a Command object reference, or returns a String value that indicates the data source of the Recordset object
设置一个字符串值,或是一个Command[指令]对象参数,或是返回一个字符串,用于知名Recordset[记录集]对象的数据源
State Returns a value that describes if the Recordset object is open, closed, connecting, executing or retrieving data
返回一个用于描述对象是否已经打开、关闭或正在执行以及是否正在提取数据的值
Status Returns the status of the current record with regard to batch updates or other bulk operations
返回进行批量更新或大量操作的当前记录的状态
StayInSync Sets or returns whether the reference to the child records will change when the parent record position changes
设置或返回一个逻辑值,用于指示当父记录的位置发生更改时,子记录的相关参数是否也需要更改

Methods
方法

Method方法 Description描述
AddNew

Creates a new record
创建一条新记录

Cancel Cancels an execution
取消执行程序
CancelBatch Cancels a batch update
取消批量更新[batch update]
CancelUpdate

Cancels changes made to a record of a Recordset object
取消对当前记录集对象所作的任何更改或放弃新添加的记录

Clone Creates a duplicate of an existing Recordset
创建一个现存记录集的复版(即:复制一个当前记录集)
Close Closes a Recordset
关闭一个记录集
CompareBookmarks Compares two bookmarks
比较两个书签
Delete Deletes a record or a group of records
删除一条或一组记录
Find Searches for a record in a Recordset that satisfies a specified criteria
按照具体制定的规则在记录集中搜索一条记录
GetRows Copies multiple records from a Recordset object into a two-dimensional array
将一个记录集对象中的多个记录复制到一个二维数组中
GetString Returns a Recordset as a string
以字符串的形式返回一个指定的记录集
Move Moves the record pointer in a Recordset object
在一个记录集对象中移动记录指针
MoveFirst Moves the record pointer to the first record
将记录指针移动到记录集中的第一条记录
MoveLast Moves the record pointer to the last record
将记录指针移动到记录集中的最后一条记录
MoveNext Moves the record pointer to the next record
将记录指针移动到记录集中的下一条记录
MovePrevious Moves the record pointer to the previous record
将记录指针移动到记录集中的上一条记录
NextRecordset Clears the current Recordset object and returns the next Recordset object by looping through a series of commands
清除当前记录集对象并通过循环执行一系列指令返回下一个记录集
Open Opens a database element that gives you access to records in a table, the results of a query, or to a saved Recordset
打开一个数据库元素,使你可以访问表格中的数据、查询结果或访问一个已存的记录集
Requery Updates the data in a Recordset by re-executing the query that made the original Recordset
通过重新执行对象所基于的查询语句,更新Recordset[记录集]对象中的数据
Resync Refreshes the data in the current Recordset from the original database
刷新Recordset[记录集]对象中的数据
Save Saves a Recordset object to a file or a Stream object
将一个Recordset[记录集]对象保存到一个文件中或保存到一个Stream对象中
Seek Searches the index of a Recordset to find a record that matches the specified values
搜索一个记录集的index[索引],从中查找与keyvalues参数中指定的值相匹配的一条记录
Supports Returns a boolean value that defines whether or not a Recordset object supports a specific type of functionality
返回一个逻辑值,用于指示是否需要让Recordset[记录集]对象支持指定的函数功能类型
Update Saves all changes made to a single record  in a Recordset object
将所有的更改信息保存到一个记录集中的记录中
UpdateBatch Saves all changes in a Recordset to the database. Used when working in batch update mode
将所有的Recordset[记录集]更改信息保存到数据库中

Events
事件

Note:  You cannot handle events using VBScript or JScript (only Visual Basic, Visual C++, and Visual J++ languages can handle events).
注意:你不能够通过使用VBScript 或 Jscript来处理事件。仅可以通过使用Visual Basic、Visual C++以及Visual J++语言来处理。

Event事件 Description描述
EndOfRecordset Triggered when you try to move to a record after the last record
当记录指针试图移动到记录集中最后一条记录之外时激发
FetchComplete Triggered after all records in an asynchronous operation have been fetched
在记录集提取了所有异步操作程序中的记录后被激发
FetchProgress Triggered periodically in an asynchronous operation, to state how many more records that have been fetched
在异步操作程序中被周期性的激发,作用是为了陈述被记录集获取的更多记录
FieldChangeComplete Triggered after the value of a Field object change
在一个或更多个字段对象被改变之后被激发的
MoveComplete Triggered after the current position in the Recordset has changed
在一个操作程序改变了记录集中记录的当前位置之后被激发
RecordChangeComplete Triggered after a record has changed
在一个或多个记录被更改后激发
RecordsetChangeComplete Triggered after the Recordset has changed
在记录集被更改后激发
WillChangeField Triggered before the value of a Field object change
在一个或更多个的字段对象改变之前被激发
WillChangeRecord Triggered before a record change
在一个或多个记录被更改前激发
WillChangeRecordset Triggered before a Recordset change
在记录集被更改前激发
WillMove Triggered before the current position in the Recordset changes
在一个操作程序改变了记录集中记录的当前位置之前被激发

Collections
集合

Collection集合 Description描述
Fields Indicates the number of Field objects in the Recordset object
指示记录集对象中字段对象的数量
Properties Contains all the Property objects in the Recordset object
指示包含记录集对象中的所有属性对象

The Fields Collection's Properties
字段集合属性

Property属性 Description描述
Count Returns the number of items in the fields collection. Starts at zero.
返回字段集合中项的数量。起点为0

Example:
案例

countfields = rs.Fields.Count 

Item(named_item/number) Returns a specified item in the fields collection.
返回字段集合中的一个指定项

Example:
案例

itemfields = rs.Fields.Item(1)
or
itemfields = rs.Fields.Item("Name")

The Properties Collection's Properties
属性集合中的属性描述

Property属性 Description描述
Count Returns the number of items in the properties collection. Starts at zero.
返回属性集合中项的数量。起点为0

Example:
案例

countprop = rs.Properties.Count 

Item(named_item/number) Returns a specified item in the properties collection.
返回属性集合中的一个指定项

Example:
案例

itemprop = rs.Properties.Item(1)
or
itemprop = rs.Properties.Item("Name")

评论 (0) All

登陆 | 还没注册?