vb.net数据库异步 *** 作(二)

vb.net数据库异步 *** 作(二),第1张

概述  ‘进行详细说明 Imports System.Data.SqlClientImports System.ThreadingModule Program Sub Main() ’输入异步 *** 作结果 Console.WriteLine("***** Fun with ASNYC Data Readers *****" & vbLf)
‘进行详细说明
imports System.Data.sqlClIEntimports System.ThreadingModule Program    Sub Main()        ’输入异步 *** 作结果 
        Console.Writeline("***** Fun with ASNYC Data Readers *****" & vbLf)        ' Create and open a connection that is async-aware.        '创建并打开一个异步连接
         Dim cn As New sqlConnection()        cn.ConnectionString = "Data Source=(local)" & _        ";Integrated Security=sspI;" & _        "Initial Catalog=newdb;Asynchronous Processing=true"        ‘ Asynchronous Processing=true 这个是必须的
        cn.open()        ' Create a sql command object that waits for approx 2 seconds.        '两秒后执行sql
        Dim strsql As String = "WaitFor Delay '00:00:02';Select * From tbdata"        Dim myCommand As New sqlCommand(strsql,cn)        ' Execute the reader on a second thread.         ' 定义异步线程并启用第二线程
        Dim itfAsynch As IAsyncResult        itfAsynch = myCommand.BeginExecuteReader(CommandBehavior.CloseConnection)
        '当线程执行时,执行其它工作        ' Do something while other thread works.         While Not itfAsynch.IsCompleted            Console.Writeline("Working on main thread...")            'Thread.Sleep(1000)        End While        Console.Writeline()         ’所有完成后,读出所有数据
        ' All done! Get reader and loop over results.         Dim myDataReader As sqlDataReader = myCommand.EndExecuteReader(itfAsynch)        While myDataReader.Read()            Console.Writeline("-> 序号: {0},临时号: {1},车船号: {2}.",_                              myDataReader("ID").ToString().Trim(),_                              myDataReader("序号").ToString().Trim(),_                              myDataReader("车船号").ToString().Trim())        End While        myDataReader.Close()        Console.Readline()    End SubEnd Module
总结

以上是内存溢出为你收集整理的vb.net数据库异步 *** 作(二)全部内容,希望文章能够帮你解决vb.net数据库异步 *** 作(二)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1291237.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存