ADO.NET Provider for SAP ERP

Build 24.0.9060

Querying with the DataAdapter

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

Using the SAPERPDataAdapter

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 SAPERPDataAdapter is slower than the SAPERPDataReader because the Fill method needs to retrieve all data from the data source before returning.

The following example selects the MANDT and MATNR columns of the MARA table:

C#

string connectionString = "Host=sap.mydomain.com;User=EXT90033;Password=xxx;Client=800;System Number=09;ConnectionType=Classic;";

using (SAPERPConnection connection = new SAPERPConnection(connectionString)) {
  SAPERPDataAdapter dataAdapter = new SAPERPDataAdapter(
  "SELECT MANDT, MATNR FROM MARA", connection);

  DataTable table = new DataTable();
  dataAdapter.Fill(table);

  Console.WriteLine("Contents of MARA.");

  foreach (DataRow row in table.Rows) {
    Console.WriteLine("{0}: {1}", row["MANDT"], row["MATNR"]);
  }
}

VB.NET

Dim connectionString As String = "Host=sap.mydomain.com;User=EXT90033;Password=xxx;Client=800;System Number=09;ConnectionType=Classic;"

Using connection As New SAPERPConnection(connectionString)
  Dim dataAdapter As New SAPERPDataAdapter("SELECT MANDT, MATNR FROM MARA", connection)

  Dim table As New DataTable()
  dataAdapter.Fill(table)

  Console.WriteLine("Contents of MARA.")

  For Each row As DataRow In table.Rows
    Console.WriteLine("{0}: {1}", row("MANDT"), row("MATNR"))
  Next
End Using

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