Public Sub Async_Exec(ByVal db2Connection As DB2Connection)
Dim db2Command As New DB2Command("SELECT * FROM Dept", db2Connection)
Console.WriteLine("Starting asynchronous retrieval of data...")
db2Connection.Open()
Dim cres As IAsyncResult = db2Command.BeginExecuteReader(Nothing, Nothing, CommandBehavior.Default)
If cres.IsCompleted Then
Console.WriteLine("Completed.")
Else
Console.WriteLine("Have to wait for operation to complete...")
End If
Dim db2Reader As DB2DataReader = db2Command.EndExecuteReader(cres)
Try
While db2Reader.Read()
Console.WriteLine(String.Concat(db2Reader.GetInt32(0), " ", db2Reader.GetString(1), " ", db2Reader.GetString(2)))
End While
Finally
db2Reader.Close()
db2Connection.Close()
End Try
End Sub