编程william hill官网
直播中

电子工程师

21年用户 16604经验值
擅长:可编程逻辑 模拟技术 测量仪表 控制/MCU RF/无线 MEMS/传感技术
私信 关注

State 属性范例 (VB)

State 属性范例 (VB)



本范例使用 State 属性,在异步连接为开且异步命令正在执行时显示消息。


Public Sub StateX()


    Dim cnn1 As ADODB.Connection
    Dim cnn2 As ADODB.Connection
    Dim cmdChange As ADODB.Command
    Dim cmdRestore As ADODB.Command
    Dim strCnn As String
   
    ' Open two asynchronous connections, displaying
    ' a message while connecting.
    Set cnn1 = New ADODB.Connection
    Set cnn2 = New ADODB.Connection
    strCnn = "Provider=sqloledb;" & _
        "Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "
       
    cnn1.Open strCnn, , , adAsyncConnect
    While (cnn1.State = adStateConnecting)
        Debug.Print "Opening first connection...."
    Wend
   
    cnn2.Open strCnn, , , adAsyncConnect
    While (cnn2.State = adStateConnecting)
        Debug.Print "Opening second connection...."
    Wend
   
    ' Create two command objects.
    Set cmdChange = New ADODB.Command
    cmdChange.ActiveConnection = cnn1
    cmdChange.CommandText = "UPDATE Titles SET type = 'self_help' " & _
        "WHERE type = 'psychology'"
   
    Set cmdRestore = New ADODB.Command
    cmdRestore.ActiveConnection = cnn2
    cmdRestore.CommandText = "UPDATE Titles SET type = 'psychology' " & _
        "WHERE type = 'self_help'"
   
    ' Executing the commands, displaying a message
    ' while they are executing.
    cmdChange.Execute , , adAsyncExecute
    While (cmdChange.State = adStateExecuting)
        Debug.Print "Change command executing...."
    Wend
   
    cmdRestore.Execute , , adAsyncExecute
    While (cmdRestore.State = adStateExecuting)
        Debug.Print "Restore command executing...."
    Wend
   
    cnn1.Close
    cnn2.Close


End Sub


 

更多回帖

发帖
×
20
完善资料,
赚取积分