Access编程交流网
  • 设为首页|收藏本站|繁体中文|手机版
  •     
  • Access培训-Access开发平台-Access行业开发

  • 首页
  • 资讯
  • 技巧
  • 源码
  • 行业
  • 资源
  • 活动
  • 关于

技巧

ACCESS数据库

启动/设置/选项/背景

修复/压缩

安全/加密/解密

快捷键

版本升级/其它等

数据表

命名方式/设计规范

表设计

查询

Sql语言基础

选择查询

更新查询

删除查询

追加查询

生成表查询

交叉表查询

SQL特定查询

查询参数

查询综合应用

界面/窗体/控件

标签

文本框

命令按钮

组合框/列表框

选项组/复选框/选项按钮

选项卡

子窗体

窗体本身/综合应用

其它

报表打印

报表设计

高级报表

模块/函数/VBA/API/系统

VBA基础

内置函数

调试/跟踪/Debug

模块/类模块

API/COM/系统相关

字符数字日期

网络通信游戏

加密解密安全

文件处理

经典算法

宏/菜单/工具栏/功能区

宏/脚本

菜单/工具栏

功能区/Ribbon

图表/图形/图像/多媒体

图表

图形/图像

音频

视频/动画

DAO/链接表/ADO/ADP

DAO/链接表/ODBC

ADO/RDO

ADP

ActiveX/第三方控件/插件

Treeview树控件

ListView列表控件

Toolbar工具栏控件

微软其它控件

Dbi-Tech

CodeJock

Grid++Report

FastReport

ComponentOne

加载项/插件/Addin

OFFICE集成/导入导出/交互

Excel导入导出/交互

Word导入导出/交互

PPT交互

Outlook控制/邮件

Text文本文件/INI/CSV

PDF/SWF/XML格式

CAD格式

Sharepoint/其它Office

SqlServer/其它数据库

表

视图

存储过程/触发器

函数

用户/权限/安全

调试/维护

SqlServer其它/综合

发布/打包/文档/帮助

开发版/运行时

打包/发布/部署

开发文档/帮助制作

Access完整行业系统

采购管理系统

销售管理系统

仓库管理系统

人力资源管理HRM

CRM管理系统

MRP/ERP管理系统

BRP/流程优化

其它管理系统

心得/经验/绝招
其它/杂项
Excel技巧

Excel应用与操作

Excel开发编程

Word技巧

Word应用与操作

Word开发编程

Outlook技巧

Outlook应用与操作

Outlook开发编程

热门文章

  • Access中Curren..
  • SQL语句集锦2
  • 如何得到表的所有键、键的类..
  • SQL语句集锦3
  • Access读取随机记录的..
  • ADO三大对象的属性、方法..

最新文章

  • 实验报告 --DAO与AD..
  • 用代码创建mdb格式的Ac..
  • 连接后台数据库提示 无法启..
  • 64位windows系统如..
  • Access的DAO准确获..
  • 利用代码自动创建ODBC源

联系方式

Access交流网(免费Access交流)

QQ:18449932 

网  址:www.access-cn.com

当前位置:首页 > 技巧 > DAO/链接表/ADO/ADP
DAO/链接表/ADO/ADP

如何使用ADO的FetchProgress和FetchComplete事件

原文: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 SUMMARY
MORE INFORMATION MORE INFORMATION
REFERENCES 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.

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:
Microsoft Data Access Components
• 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:
Visual Studio Product Updates
Coding Requirements
• 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

FetchProgress

FetchProgress 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

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:
   Option Explicit

   Const strConn = "DSN=Pubs"
   Const strDefaultSQL = "SELECT * FROM Titles"

   Dim cn As ADODB.Connection
   Dim WithEvents rs As ADODB.Recordset

   Private Sub Form_Load()
      Command1.Caption = "Go"
      Text1.Text = strDefaultSQL

      Set cn = New ADODB.Connection
      cn.Open strConn
   End Sub

   Private Sub Command1_Click()
      Dim strSQL As String
      strSQL = Text1.Text

      Set rs = New ADODB.Recordset
      With rs
         .CursorLocation = adUseClient

         .Properties("Initial Fetch Size") = 2
         .Properties("Background Fetch Size") = 4

         Debug.Print "Start"
         Debug.Print "Initial Fetch Size: " & _
                     .Properties("Initial Fetch Size")
         Debug.Print "Background Fetch Size" & _
                     .Properties("Background Fetch Size")

         .Open strSQL, cn, , , adAsyncFetch
      End With
   End Sub

   Private Sub rs_FetchProgress(ByVal Progress As Long, _
                                ByVal MaxProgress As Long, _
                                adStatus As ADODB.EventStatusEnum, _
                                ByVal pRecordset As ADODB.Recordset)

      Debug.Print "Fetch: " & Progress & _
                  "  Max: " & MaxProgress

   End Sub

   Private Sub rs_FetchComplete(ByVal pError As ADODB.Error, _
                                adStatus As ADODB.EventStatusEnum, _
                                ByVal pRecordset As ADODB.Recordset)

      If adStatus <> adStatusOK Then
         Debug.Print "Failed"
         Debug.Print "Error: " & pError.Number & " - " & pError.Description
      Else
         Set DataGrid1.DataSource = pRecordset
         Debug.Print "Done"
      End If

   End Sub
					
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

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:
258904 BUG: FetchProgress Returns Incorrect Data with MDAC 2.1
224332 PRB: ADO Recordset Opened with adAsyncFetch May Seem Synchronous
发布人:Microsof…-Microsoft  
分享到:
点击次数:  更新时间:2005-02-06 11:16:46  【打印此页】  【关闭】
上一条:ADO的IsolationLevel  下一条:如何将RECORDSET的结果集保存XML文件



相关文章

  • • 实验报告 --DAO与ADO效率之比较
  • • 用代码创建mdb格式的Access文件
  • • 连接后台数据库提示 无法启动应用程序。工作组信息文件丢失,或是已被其它用户以独占方式打开 的解决办法
  • • 64位windows系统如何使用64位的ADO连接Accesss accdb数据库(ACE.OLEDB)
  • • Access的DAO准确获取记录集Recordset的记录数Recordcount
  • • 利用代码自动创建ODBC源
  • • 在打开Ado记录集之前尽量先判断记录集有否打开,如打开则先关闭之
  • • 快速获取Excel文件所有工作表表名

热门文章

  • [2014-01-02] Access开发网络共享版技巧(多人同时操作)access数据库
  • [2017-05-27] 利用代码自动创建ODBC源access数据库
  • [2005-02-18] SQL语句集锦4access数据库
  • [2004-11-23] 一句代码得到SQL SERVER时间的函数access数据库
  • [2005-02-18] 跟我学SQLaccess数据库
  • [2005-02-05] 打开带密码的数据库/修改密码/创建组和用户access数据库

热门产品

公司动态|在线留言|在线反馈|友情链接|会员中心|站内搜索|网站地图

中山市天鸣科技发展有限公司 版权所有 1999-2023 粤ICP备10043721号

QQ:18449932

Access应用 Access培训 Access开发 Access平台

access|数据库|access下载|access教程|access视频|access软件

Powered by MetInfo 5.3.12 ©2008-2025  www.metinfo.cn