ADO.NET Provider for Sage 300

Build 24.0.8963

Querying with the DataReader

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

Using the Sage300DataReader

The Sage300DataReader retrieves data faster than the Sage300DataAdapter because it can retrieve data in pages. As you read data from the Sage300DataReader, 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 OEInvoices table:

C#

string connectionString = "User=SAMPLE;Password=password;URL=http://127.0.0.1/Sage300WebApi/v1/-/;Company=SAMINC;";

using (Sage300Connection connection = new Sage300Connection(connectionString)) {
  Sage300Command cmd = new Sage300Command("SELECT * FROM OEInvoices", connection);
  
  Sage300DataReader rdr = cmd.ExecuteReader();

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

VB.NET

Dim connectionString As String = "User=SAMPLE;Password=password;URL=http://127.0.0.1/Sage300WebApi/v1/-/;Company=SAMINC;"

Using connection As New Sage300Connection(connectionString)
  Dim cmd As New Sage300Command("SELECT * FROM OEInvoices", connection)

  Dim rdr As Sage300DataReader = cmd.ExecuteReader()

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

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