编程论坛
400万+工程师在用
400万+工程师在用

电子发烧友网工程师

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

State 属性范例 (VB)

2009-1-8 10:25

<p><font face="Verdana">State 属性范例 (VB)</font></p><font face="Verdana">
<p><br/>本范例使用 State 属性,在异步连接为开且异步命令正在执行时显示消息。</p>
<p>Public Sub StateX()</p>
<p>&nbsp;&nbsp;&nbsp; Dim cnn1 As ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; Dim cnn2 As ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; Dim cmdChange As ADODB.Command<br/>&nbsp;&nbsp;&nbsp; Dim cmdRestore As ADODB.Command<br/>&nbsp;&nbsp;&nbsp; Dim strCnn As String<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Open two asynchronous connections, displaying<br/>&nbsp;&nbsp;&nbsp; ' a message while connecting.<br/>&nbsp;&nbsp;&nbsp; Set cnn1 = New ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; Set cnn2 = New ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; strCnn = "Provider=sqloLEDb;" &amp; _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; cnn1.Open strCnn, , , adAsyncConnect<br/>&nbsp;&nbsp;&nbsp; While (cnn1.State = adStateConnecting)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; debug.Print "Opening first connection...."<br/>&nbsp;&nbsp;&nbsp; Wend<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; cnn2.Open strCnn, , , adAsyncConnect<br/>&nbsp;&nbsp;&nbsp; While (cnn2.State = adStateConnecting)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print "Opening second connection...."<br/>&nbsp;&nbsp;&nbsp; Wend<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Create two command objects.<br/>&nbsp;&nbsp;&nbsp; Set cmdChange = New ADODB.Command<br/>&nbsp;&nbsp;&nbsp; cmdChange.ActiveConnection = cnn1<br/>&nbsp;&nbsp;&nbsp; cmdChange.CommandText = "UPDATE Titles SET type = 'self_help' " &amp; _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "WHERE type = 'psychology'"<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set cmdRestore = New ADODB.Command<br/>&nbsp;&nbsp;&nbsp; cmdRestore.ActiveConnection = cnn2<br/>&nbsp;&nbsp;&nbsp; cmdRestore.CommandText = "UPDATE Titles SET type = 'psychology' " &amp; _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "WHERE type = 'self_help'"<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Executing the commands, displaying a message<br/>&nbsp;&nbsp;&nbsp; ' while they are executing.<br/>&nbsp;&nbsp;&nbsp; cmdChange.Execute , , adAsyncExecute<br/>&nbsp;&nbsp;&nbsp; While (cmdChange.State = adStateExecuting)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print "Change command executing...."<br/>&nbsp;&nbsp;&nbsp; Wend<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; cmdRestore.Execute , , adAsyncExecute<br/>&nbsp;&nbsp;&nbsp; While (cmdRestore.State = adStateExecuting)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print "Restore command executing...."<br/>&nbsp;&nbsp;&nbsp; Wend<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; cnn1.Close<br/>&nbsp;&nbsp;&nbsp; cnn2.Close</p>
<p>End Sub</p>
<p></font>&nbsp;</p>

更多回帖

打开APP