EndExecuteReader Method (OracleCommand)
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
OracleDataReader and rendered to the console.
|
|---|
Public void Async_Exec(OracleConnection oracleConnection)
{
OracleCommand oracleCommand = new OracleCommand("SELECT * FROM Test.Dept",oracleConnection);
Console.WriteLine("Starting asynchronous retrieval of data...");
oracleConnection.Open();
IAsyncResult cres = oracleCommand.BeginExecuteReader(null,null,CommandBehavior.Default);
if (cres.IsCompleted)
Console.WriteLine("Completed.");
else
Console.WriteLine("Have to wait for operation to complete...");
OracleDataReader oracleReader = oracleCommand.EndExecuteReader(cres);
try
{
while (oracleReader.Read())
{
Console.WriteLine(oracleReader.GetInt32(0) + " " + oracleReader.GetString(1) + " " + oracleReader.GetString(2));
}
}
finally
{
oracleReader.Close();
oracleConnection.Close();
}
} |
|
|---|
Public Sub Async_Exec(ByVal oracleConnection As OracleConnection)
Dim oracleCommand As New OracleCommand("SELECT * FROM Test.Dept", oracleConnection)
Console.WriteLine("Starting asynchronous retrieval of data...")
oracleConnection.Open()
Dim cres As IAsyncResult = oracleCommand.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 oracleReader As OracleDataReader = oracleCommand.EndExecuteReader(cres)
Try
While oracleReader.Read()
Console.WriteLine(String.Concat(oracleReader.GetInt32(0), " ", oracleReader.GetString(1), " ", oracleReader.GetString(2)))
End While
Finally
oracleReader.Close()
oracleConnection.Close()
End Try
End Sub |