ADO.NET Provider for SAP Business One

Build 23.0.8839

Querying with the DataAdapter

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

Using the SAPBusinessOneDataAdapter

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

The following example selects the DocEntry and DocType columns of the Orders table:

C#

string connectionString = "Url=http://localhost:50000/b1s/v1;User=username;Password=password;CompanyDB=dbname;";

using (SAPBusinessOneConnection connection = new SAPBusinessOneConnection(connectionString)) {
  SAPBusinessOneDataAdapter dataAdapter = new SAPBusinessOneDataAdapter(
  "SELECT DocEntry, DocType FROM Orders", connection);

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

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

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

VB.NET

Dim connectionString As String = "Url=http://localhost:50000/b1s/v1;User=username;Password=password;CompanyDB=dbname;"

Using connection As New SAPBusinessOneConnection(connectionString)
  Dim dataAdapter As New SAPBusinessOneDataAdapter("SELECT DocEntry, DocType FROM Orders", connection)

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

  Console.WriteLine("Contents of Orders.")

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

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