如何使用ADO的FetchProgress和FetchComplete事件
时间:2005-02-06 11:16 来源:Microsoft 作者:Microsof… 阅读:次
原文:http://support.microsoft.com/default.aspx?kbid=262311
How To Use the ADO FetchProgress and FetchComplete Events
Article ID | : | 262311 |
Last Review | : | July 13, 2004 |
Revision | : | 1.0 |
This article was previously published under Q262311
On this page
SUMMARY | ||
MORE INFORMATION | ||
REFERENCES |
SUMMARY
The FetchProgress and FetchComplete events are used to monitor the loading of a recordset, when loading the recordset asynchronously.
The FetchProgress event gives you information on the current state of the recordset, which can be used to display a progress indicator to the user.
The FetchComplete event is fired when the recordset is finished loading.
The FetchProgress event gives you information on the current state of the recordset, which can be used to display a progress indicator to the user.
The FetchComplete event is fired when the recordset is finished loading.
MORE INFORMATION
Prerequisites
Software Requirements• | The FetchProgress and FetchComplete events only work properly in MDAC 2.5 or later. You can download the latest version of the Microsoft Data access Components from the following Microsoft Web site: |
• | If you are developing your application in Microsoft Visual Studio 6.0, then you must have service pack 3 or later installed. You can install the latest service pack for Microsoft Visual Studio 6.0 from the following Microsoft Web site: |
• | When you open the recordset, you must specify adAsyncFetch as a Recordset Option. |
• | You must use client-side cursors, because the FetchProgress and FetchComplete events are returned by the ActiveX Data Objects (ADO) client cursor engine. |
• | In Visual Basic, you must declare the Recordset at module level using Dim with the WithEvents keyword. |
Properties
There are two recordset properties that affect the asynchronous behavior of ADO. These properties should be set prior to opening the recordset.• | Initial Fetch Size determines how many records are fetched synchronously before the asynchronous thread is created. This allows for a small recordset to be created without the additional overhead of creating a thread. This is set to 50 by default. To guarantee that FetchProgress and FetchComplete are called, set this value to 0. |
• | Background Fetch Size determines how many records are fetched between calls to the FetchProgress event. This is set to 15 by default. |
The Events
FetchProgressFetchProgress has four Parameters:
• | Progress is the number of records currently in the recordset. The first time FetchProgress is called, Progress is equal to Initial Fetch Size plus Background Fetch Size. For each additional call, Progress equals the previous value plus Background Fetch Size. |
• | MaxProgress is the maximum value expected to be returned. MaxProgress is not equal to the actual number of records that will be returned. ADO has to fetch the records in order to get this value. This means MaxProgress is only ever a best guess. MaxProgress usually equals Progress plus Background Fetch Size. FetchProgess is always called before calling FetchComplete. In this case, Progress and MaxProgress are equal to each other. This MaxProgress equals the actual number of records retrieved. |
• | The value of adStatus determines if any errors have occurred. This value is normally adStatusOK. You may disable the FetchProgress event by setting the value of adStatus to the value adStatusUnwantedEvent. |
• | pRecordset is a reference to the recordset itself. |
FetchComplete has three Parameters:
• | If adStatus is adStatusErrorsOccurred, then you can check pError to determine what error has occurred. This can happen if your code calls the Cancel method before the query is done executing, for example. |
• | The value of adStatus determines if any errors have occurred. You may disable the FetchComplete event by setting the value of adStatus to the value adStatusUnwantedEvent. |
• | pRecordset is a reference to the recordset itself. |
Sample Code
The following sample demonstrates how to use the FetchProgress and FetchComplete events in Visual Basic.The sample uses an ODBC Datasource named Pubs to connect to the Pubs database that comes with SQL Server.
1. | In Microsoft Visual Basic, create a new Standard EXE. Form1 is added to the project by default. |
2. | On the Project menu, click to select References, and then select Microsoft ActiveX Data Objects Library. |
3. | On the Project menu, click to select Components, and then select Microsoft DataGrid Control 6.0 (OLEDB). |
4. | Place a DataGrid, a Textbox, and a CommandButton onto Form1. |
5. | Add the following code to Form1's Code Window:
|
6. | Change strConn to a valid connection string for your database, and change strDefaultSQL to a valid SQL query that returns records from your database. |
7. | Run the code. Click the Go button to start reading the Recordset. On the View menu, click to select Immediate Window. Visual Basic's Immediate window displays the progress of the asynchronous query. |
REFERENCES
(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
相关内容
- ·用DAO或ADO正确访问Access 2000
- ·Access开发网络共享版技巧(多人同时操
- ·access中ADO与DAO格式的区别和写法【总
- ·access执行操作查询的几种方法对比
- ·Access中CurrentDb().Execute 和DoCmd.
- ·[源创技巧]在ACCESS中使用代码来自动创
- ·更新访问权限 (Jet) 数据库中的 40 多
- ·【实例】ADO代码计算余额法
- ·DAO实现的子窗体记录分页显示
- ·分别使用DAO和ADO连接外部数据库和Sql
- ·怎样判断一个表是否存在于数据库中? (D
- ·处理加了密码的MDB文件
- ·谈ADO访问不同数据库的差别
- ·DAO基础(4)
- ·DAO基础(3)
- ·DAO基础(2)
最新内容
推荐内容