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