概述
Imports System.Data.SqlClient
Imports System.Threading
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BindData()
End Sub
Private Sub BindData()
Dim ConStr As String = "Data Source=.;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Pwd=sa;Asynchronous Processing=true"
Dim QueryStr As String = "select * from Customers"
Using con As SqlConnection = New SqlConnection(ConStr)
Dim cmd As SqlCommand = New SqlCommand(QueryStr, con)
Dim AsynResult As IAsyncResult
Dim Dr As SqlDataReader
Try
con.Open()
AsynResult = cmd.BeginExecuteReader(CommandBehavior.CloseConnection)
While (Not AsynResult.IsCompleted)
Console.WriteLine("异步查询方式:")
AsynResult.AsyncWaitHandle.WaitOne(1000, True)
'system.threading .thread sleep(3000);
End While
Dr = cmd.EndExecuteReader(AsynResult)
Dim bs As BindingSource = New BindingSource
bs.DataSource = Dr
DataGridView1.DataSource = bs
'While Dr.Read
' Console.WriteLine(Dr.Item(1).ToString)
'End While
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Using
End Sub
End Class
最后
以上就是可靠胡萝卜为你收集整理的vb.net异步查询方式一的全部内容,希望文章能够帮你解决vb.net异步查询方式一所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复