Querying with the DataReader
The CData ADO.NET Provider for SAP Fieldglass implements two ADO.NET interfaces you can use to retrieve data from SAP Fieldglass: SAPFieldglassDataAdapter and SAPFieldglassDataReader objects. Whereas SAPFieldglassDataAdapter objects retrieve a single result set of all the data that matches a query, SAPFieldglassDataReader objects fetch data in subset increments as needed.
Using the SAPFieldglassDataReader
The SAPFieldglassDataReader retrieves data faster than the SAPFieldglassDataAdapter because it can retrieve data in pages. As you read data from the SAPFieldglassDataReader, 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 AuditTrails table:
C#
string connectionString = "EnvironmentURL='https://myinstance.com';OAuthClientId=clientId;OAuthClientSecret=clientSecret;APIKey=xxxxxxxx-xxxx-xxxx-xxxx;"; using (SAPFieldglassConnection connection = new SAPFieldglassConnection(connectionString)) { SAPFieldglassCommand cmd = new SAPFieldglassCommand("SELECT * FROM AuditTrails", connection); SAPFieldglassDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["Id"], rdr["Category"])); } }
VB.NET
Dim connectionString As String = "EnvironmentURL='https://myinstance.com';OAuthClientId=clientId;OAuthClientSecret=clientSecret;APIKey=xxxxxxxx-xxxx-xxxx-xxxx;" Using connection As New SAPFieldglassConnection(connectionString) Dim cmd As New SAPFieldglassCommand("SELECT * FROM AuditTrails", connection) Dim rdr As SAPFieldglassDataReader = cmd.ExecuteReader() While rdr.Read() Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("Id"), rdr("Category"))) End While End Using