vb.net数据库异步操作(三)
发布时间:2020-12-16 22:48:55 所属栏目:大数据 来源:网络整理
导读:Imports System.Data.SqlClientImports System.ThreadingPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim theConnectionString As String theConnectionString = "Dat
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 Dim theConnectionString As String theConnectionString = "Data Source=WANGLI;Initial Catalog=PlcData;Persist Security Info=True;User ID=sa;pwd =sa;Asynchronous Processing=true" '这个必要加的Asynchronous Processing=true Dim theConnection As SqlConnection = New SqlConnection(theConnectionString) Dim theCommand As SqlClient.SqlCommand theCommand = New SqlCommand("select * from tbdata",theConnection) theConnection.Open() Console.WriteLine("connection open and asynchronour processing starting.") theCommand.BeginExecuteReader(New AsyncCallback(AddressOf DataReady),theCommand) End Sub ‘要执行的异步处理过程 Private Sub DataReady(ByVal asyncResult As IAsyncResult) Dim theCommand As SqlCommand = asyncResult.AsyncState Dim Dr As SqlDataReader Dr = theCommand.EndExecuteReader(asyncResult) While Dr.Read Console.WriteLine(Dr.GetString(2)) End While theCommand.Connection.Close() Console.WriteLine("数据处理结束....") End Sub vb.net数据库异步操作(二) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |