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