Start the process of retrieving a data reader asynchronously. : SqlDataReader « Database ADO.net « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Database ADO.net » SqlDataReader 
26.12.1.Start the process of retrieving a data reader asynchronously.
Imports System.Data.SqlClient

Module Module1
    Sub Main()
        Dim commandText As String = _
         "WAITFOR DELAY '00:00:03';" & _
         "SELECT LastName, FirstName FROM Person.Contact " & _
         "WHERE LastName LIKE 'M%'"

        RunCommandAsynchronously(commandText, "Data Source=(local);Integrated Security=true;Initial Catalog=AdventureWorks; Asynchronous Processing=true")

        Console.WriteLine("Press ENTER to continue.")
        Console.ReadLine()
    End Sub

    Private Sub RunCommandAsynchronously(ByVal commandText As String, ByVal connectionString As String)
        Using connection As New SqlConnection(connectionString)
           Dim command As New SqlCommand(commandText, connection)
           connection.Open()
           Dim result As IAsyncResult = command.BeginExecuteReader()
           Dim count As Integer
           While Not result.IsCompleted
               count += 1
               Console.WriteLine("Waiting ({0})", count)
               Threading.Thread.Sleep(100)
           End While
           Using reader As SqlDataReader = command.EndExecuteReader(result)
               DisplayResults(reader)
           End Using
        End Using
    End Sub

    Private Sub DisplayResults(ByVal reader As SqlDataReader)
        While reader.Read()
            For i As Integer = To reader.FieldCount - 1
                Console.Write("{0} ", reader.GetValue(i))
            Next
        End While
    End Sub

End Module
26.12.SqlDataReader
26.12.1.Start the process of retrieving a data reader asynchronously.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.