⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 如何在ado中用异步的方式打开一个recordset.txt

📁 VB技巧问答10000例 VB技巧问答10000例
💻 TXT
字号:
首先,常量应是adAsyncExecute而不是adExecuteAsync。在ADO中,Connection/Command/RecordSet对象均允许异步操作,记录集对象通过adAsyncExecute参数来实现。如果想要在异步执行过程中取消它,方法有以下几种。 
    新建一个窗体,在窗体中放置两个按钮Command1,Command2,当用户按下Command1按钮时,异步打开记录集,当用户按下Command2,取消异步操作。 
    其中blnStop,Recordset1,Connection1均为模块级变量。 
    一、使用记录集的Cancel方法和State属性。例子代码: 
    Dim recordset1 As New Recordset 
    Dim Connection1 As New Connection 
    Dim blnStop As Boolean 
     
    Private Sub Command1_Click() 
     Connection1.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=(local)" 
     Connection1.Open 
     
     
     recordset1.Open "select * from authors", Connection1, adOpenStatic, adLockReadOnly, adAsyncExecute 
     
     Do 
     If recordset1.State And adStateOpen Then 
     MsgBox "异步执行结束!" 
     Exit Do 
     Else 
     If blnStop Then 
     If CBool(recordset1.State And adStateExecuting) Then 
     recordset1.Cancel 
     MsgBox "用户取消执行!" 
     End If 
     End If 
     End If 
     DoEvents 
     
     
    Loop 
     
    End Sub 
     
    Private Sub Command2_Click() 
     blnStop = Not blnStop 
     
    End Sub 
     
     
     
    Private Sub Form_Load() 
     blnStop = False 
     
    End Sub 
<END>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -