Querying with the DataReader
The CData ADO.NET Provider for SAP Ariba Procurement implements two ADO.NET interfaces you can use to retrieve data from SAP Ariba: SAPAribaProcurementDataAdapter and SAPAribaProcurementDataReader objects. Whereas SAPAribaProcurementDataAdapter objects retrieve a single result set of all the data that matches a query, SAPAribaProcurementDataReader objects fetch data in subset increments as needed.
Using the SAPAribaProcurementDataReader
The SAPAribaProcurementDataReader retrieves data faster than the SAPAribaProcurementDataAdapter because it can retrieve data in pages. As you read data from the SAPAribaProcurementDataReader, 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 Orders table:
C#
string connectionString = "ANID=AN02000000280;API=PurchaseOrdersBuyerAPI-V1;APIKey=wWVLn7WTAXrIRMAzZ6VnuEj7Ekot5jnU;AuthScheme=OAuthClient;InitiateOAuth=GETANDREFRESH;OAuthClientId=testClient;OAuthClientSecret=testClientSecret;UseSandbox=false;"; using (SAPAribaProcurementConnection connection = new SAPAribaProcurementConnection(connectionString)) { SAPAribaProcurementCommand cmd = new SAPAribaProcurementCommand("SELECT * FROM Orders", connection); SAPAribaProcurementDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["DocumentNumber"], rdr["Revision"])); } }
VB.NET
Dim connectionString As String = "ANID=AN02000000280;API=PurchaseOrdersBuyerAPI-V1;APIKey=wWVLn7WTAXrIRMAzZ6VnuEj7Ekot5jnU;AuthScheme=OAuthClient;InitiateOAuth=GETANDREFRESH;OAuthClientId=testClient;OAuthClientSecret=testClientSecret;UseSandbox=false;" Using connection As New SAPAribaProcurementConnection(connectionString) Dim cmd As New SAPAribaProcurementCommand("SELECT * FROM Orders", connection) Dim rdr As SAPAribaProcurementDataReader = cmd.ExecuteReader() While rdr.Read() Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("DocumentNumber"), rdr("Revision"))) End While End Using