解决由于SQL查询时间长导致程序假死状态

1 首先要引用 MDAC 2.5 以上版本。使用 VB 6.0 以上平台。
2 声明变量如 Dim WithEvents rs As ADODB.Recordset
3 必须使用客户游标。
4 打开记录集时必须指定 adAsyncFetch

Dim WithEvents rs As ADODB.Recordset

Set rs = New ADODB.Recordset
With rs
     .CursorLocation = adUseClient
     
     .Properties("Initial Fetch Size") = 2
     .Properties("Background Fetch Size") = 4
     .Open strSQL, cn, , , adAsyncFetch
End With

事件:(当然你可以使用进度条)
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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值