EndExecuteReader Method (DB2Command)
Ends an asynchronous invocation of the
ExecuteReader method.
In the example below an easiest way of executing an asynchronous operation is shown. First, all components are set up and a connection is opened. Second, a data retrieval operation is started. The operation state (done or in progress) is checked and a report is written to the console. At last query results are sent to
DB2DataReader and rendered to the console.
Public void Async_Exec(DB2Connection db2Connection)
{
DB2Command db2Command = new DB2Command("SELECT * FROM Dept",db2Connection);
Console.WriteLine("Starting asynchronous retrieval of data...");
db2Connection.Open();
IAsyncResult cres = db2Command.BeginExecuteReader(null,null,CommandBehavior.Default);
if (cres.IsCompleted)
Console.WriteLine("Completed.");
else
Console.WriteLine("Have to wait for operation to complete...");
DB2DataReader db2Reader = db2Command.EndExecuteReader(cres);
try
{
while (db2Reader.Read())
{
Console.WriteLine(db2Reader.GetInt32(0) + " " + db2Reader.GetString(1) + " " + db2Reader.GetString(2));
}
}
finally
{
db2Reader.Close();
db2Connection.Close();
}
}
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
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2