我是靠谱客的博主 可靠胡萝卜,最近开发中收集的这篇文章主要介绍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 Sub
End Class

最后

以上就是可靠胡萝卜为你收集整理的vb.net异步查询方式一的全部内容,希望文章能够帮你解决vb.net异步查询方式一所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部