由于是基于上千万级别的查询,每次查询可能要花5、6分钟以上,此时vb程序几乎死机状态,用户也没法知道进度情况,请问有没有什么办法避免这种情况,甚至有没有可能使用进度条?谢谢

解决方案 »

  1.   

    有办法。
    1 首先要引用 MDAC 2.5 以上版本。使用 VB 6.0 以上平台。
    2 声明变量如 Dim WithEvents rs As ADODB.Recordset
    3 必须使用客户游标。
    4 打开记录集时必须指定 adAsyncFetch Dim WithEvents rs As ADODB.RecordsetSet 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 SubPrivate 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
      

  2.   

    我晕,强烈建议csdn搞个引用功能~~郁闷