ADO.NET Provider for SAP Cloud for Customer

Build 23.0.8839

Querying with the DataReader

The CData ADO.NET Provider for SAP Cloud for Customer implements two ADO.NET interfaces you can use to retrieve data from SAP Cloud for Customer: SAPHybrisC4CDataAdapter and SAPHybrisC4CDataReader objects. Whereas SAPHybrisC4CDataAdapter objects retrieve a single result set of all the data that matches a query, SAPHybrisC4CDataReader objects fetch data in subset increments as needed.

Using the SAPHybrisC4CDataReader

The SAPHybrisC4CDataReader retrieves data faster than the SAPHybrisC4CDataAdapter because it can retrieve data in pages. As you read data from the SAPHybrisC4CDataReader, it periodically requests the next page of results from the data source, if required. This causes results to be returned at a faster rate. The following example selects all the columns from the AccountCollection table:

C#

string connectionString = "User=user;Password=password;";

using (SAPHybrisC4CConnection connection = new SAPHybrisC4CConnection(connectionString)) {
  SAPHybrisC4CCommand cmd = new SAPHybrisC4CCommand("SELECT * FROM AccountCollection", connection);
  
  SAPHybrisC4CDataReader rdr = cmd.ExecuteReader();

  while (rdr.Read()) {
    Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["ObjectID"], rdr["AccountName"]));
  }
}

VB.NET

Dim connectionString As String = "User=user;Password=password;"

Using connection As New SAPHybrisC4CConnection(connectionString)
  Dim cmd As New SAPHybrisC4CCommand("SELECT * FROM AccountCollection", connection)

  Dim rdr As SAPHybrisC4CDataReader = cmd.ExecuteReader()

  While rdr.Read()
    Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("ObjectID"), rdr("AccountName")))
  End While
End Using

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839