DB2DataReader.NextResultAsync Method
An asynchronous version of NextResult, which advances the reader to the next result when reading the results of a batch of statements. Invokes NextResultAsync with CancellationToken.None. (Inherited from DbDataReader.)
- Namespace:
IBM.Data.DB2- Assembly:
IBM.Data.DB2(inIBM.Data.DB2.dll)
Syntax
[Visual Basic]
Public Function NextResultAsync As Task(Of Boolean)
[C#]
public Task< bool> NextResultAsync()
[C++]
Task<bool>^ NextResultAsync()
[JScript]
public function NextResultAsync() : Task< boolean >
Return value
A task representing the asynchronous operation.
Remarks
The first level support of DB2DataReader.NextResultAsync uses a mix of asynchronous and synchronous code due to dependencies on unmanaged components such as CSM, HADR and DRDA.
Example
// Customer
private struct Customer
{
public long CustomerID;
public string FirstName;
public string LastName;
}
// Gets the specific customer by reading the next result set asynchronously
private async Task <Customer> GetCustomerAsync( string myConnString)
{
// This simple select query fetches thousands of rows from an existing CUSTOMERS table,
// and may require handling of network packets asynchronously by calling DB2DataReader.ReadAsync()
string mySelectQuery = "SELECT * FROM CUSTOMERS; SELECT TOP 1 * FROM CUSTOMERS ORDER BY LastName" ;
using (DB2Connection myConnection = new DB2Connection(myConnString))
{
myConnection.Open();
Customer customer = new Customer();
using (DB2Command myCommand = new DB2Command(mySelectQuery, myConnection))
{
using (DB2DataReader myReader = myCommand.ExecuteReader())
{
if (awaitmyReader.ReadAsync())
{
// Do some operations...
}
//This will allow leftover rows in the first result set to be read off asynchronously
if ( await myReader.NextResultAsync())
{
if ( await myReader.ReadAsync())
{
// Get the second Result Set's Customer i.e. the first Customer sorted by LastName
customer.CustomerID = myReader.GetInt64(0);
customer.FirstName = myReader.GetString(1);
customer.LasttName = myReader.GetString(2);
}
}
}
}
return customer;
}