Querying with the DataReader
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 SAPBusinessOneDataReader
The SAPBusinessOneDataReader retrieves data faster than the SAPBusinessOneDataAdapter because it can retrieve data in pages. As you read data from the SAPBusinessOneDataReader, 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 = "Url=http://localhost:50000/b1s/v1;User=username;Password=password;CompanyDB=dbname;"; using (SAPBusinessOneConnection connection = new SAPBusinessOneConnection(connectionString)) { SAPBusinessOneCommand cmd = new SAPBusinessOneCommand("SELECT * FROM Orders", connection); SAPBusinessOneDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["DocEntry"], rdr["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 cmd As New SAPBusinessOneCommand("SELECT * FROM Orders", connection) Dim rdr As SAPBusinessOneDataReader = cmd.ExecuteReader() While rdr.Read() Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("DocEntry"), rdr("DocType"))) End While End Using