DB2DataReader.ReadAsync Method

An asynchronous version of Read, which advances the reader to the next record in a result set. This method invokes ReadAsync with CancellationToken.None. (Inherited from DbDataReader.)

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax


[Visual Basic]
Public Function ReadAsync As Task(Of Boolean)
[C#]
public Task<bool> ReadAsync()
[C++]
public: Task<bool>^ ReadAsync()
[JScript]
public function ReadAsync() : Task<boolean>

Return value

A task representing the asynchronous operation.

Remarks

If the behavior parameter of ExecuteReaderAsync is set to Default , ReadAsync reads the entire row before returning the Task.

The first level support of DB2DataReader.ReadAsync 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;
}
// Reads CUSTOMERS table asynchronously
private async Task<List<Customer>> ReadCustomerDataAsync(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";
using  (DB2Connection myConnection =  new  DB2Connection(myConnString))
{
  using  (DB2DataReader myReader = myCommand.ExecuteReader())
  {
    //Read Customers data asynchronously
   while  (  await  myReader.ReadAsync())
      {
        // Populate list of Customers here...
        customers.Add(  new  Customer(myReader.GetInt64(0),
           myReader.GetString(1)),
           myReader.GetString(2));
      }
     }
   }

   return customers;
}