vb.net异步查询方式一

前端之家收集整理的这篇文章主要介绍了vb.net异步查询方式一前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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 SubEnd Class

原文链接:https://www.f2er.com/vb/261078.html

猜你在找的VB相关文章