Querying with the DataAdapter
The CData ADO.NET Provider for SAP Ariba Source implements two ADO.NET interfaces you can use to retrieve data from SAP Ariba: SAPAribaSourceDataAdapter and SAPAribaSourceDataReader objects. Whereas SAPAribaSourceDataAdapter objects retrieve a single result set of all the data that matches a query, SAPAribaSourceDataReader objects fetch data in subset increments as needed.
Using the SAPAribaSourceDataAdapter
Use the adapter's Fill method to retrieve data from the data source. An empty DataTable instance is passed as an argument to the Fill method. When the method returns, the DataTable instance is populated with the queried data. Note that the SAPAribaSourceDataAdapter is slower than the SAPAribaSourceDataReader because the Fill method needs to retrieve all data from the data source before returning.
The following example selects the SMVendorID and Category columns of the Vendors table:
C#
string connectionString = "API=SupplierDataAPIWithPagination-V4;APIKey=wWVLn7WTAXrIRMAzZ6VnuEj7Ekot5jnU;Environment=SANDBOX;Realm=testRealm;AuthScheme=OAuthClient;InitiateOAuth=GETANDREFRESH;OAuthClientId=testClient;OAuthClientSecret=testClientSecret;"; using (SAPAribaSourceConnection connection = new SAPAribaSourceConnection(connectionString)) { SAPAribaSourceDataAdapter dataAdapter = new SAPAribaSourceDataAdapter( "SELECT SMVendorID, Category FROM Vendors", connection); DataTable table = new DataTable(); dataAdapter.Fill(table); Console.WriteLine("Contents of Vendors."); foreach (DataRow row in table.Rows) { Console.WriteLine("{0}: {1}", row["SMVendorID"], row["Category"]); } }
VB.NET
Dim connectionString As String = "API=SupplierDataAPIWithPagination-V4;APIKey=wWVLn7WTAXrIRMAzZ6VnuEj7Ekot5jnU;Environment=SANDBOX;Realm=testRealm;AuthScheme=OAuthClient;InitiateOAuth=GETANDREFRESH;OAuthClientId=testClient;OAuthClientSecret=testClientSecret;" Using connection As New SAPAribaSourceConnection(connectionString) Dim dataAdapter As New SAPAribaSourceDataAdapter("SELECT SMVendorID, Category FROM Vendors", connection) Dim table As New DataTable() dataAdapter.Fill(table) Console.WriteLine("Contents of Vendors.") For Each row As DataRow In table.Rows Console.WriteLine("{0}: {1}", row("SMVendorID"), row("Category")) Next End Using