Querying with the DataReader
The CData ADO.NET Provider for Sage X3 Cloud implements two ADO.NET interfaces you can use to retrieve data from Sage X3 Cloud: SageX3CloudDataAdapter and SageX3CloudDataReader objects. Whereas SageX3CloudDataAdapter objects retrieve a single result set of all the data that matches a query, SageX3CloudDataReader objects fetch data in subset increments as needed.
Using the SageX3CloudDataReader
The SageX3CloudDataReader retrieves data faster than the SageX3CloudDataAdapter because it can retrieve data in pages. As you read data from the SageX3CloudDataReader, 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 Customer table:
C#
string connectionString = "URL=https://x3server/;OAuthAccessTokenUrl=https://auth-domain/oauth/token;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;Audience=https://api-audience;XAPIKey=your_api_key;Folder=SEED;";
using (SageX3CloudConnection connection = new SageX3CloudConnection(connectionString)) {
SageX3CloudCommand cmd = new SageX3CloudCommand("SELECT * FROM Customer", connection);
SageX3CloudDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) {
Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["Name"], rdr["Description"]));
}
}
VB.NET
Dim connectionString As String = "URL=https://x3server/;OAuthAccessTokenUrl=https://auth-domain/oauth/token;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;Audience=https://api-audience;XAPIKey=your_api_key;Folder=SEED;"
Using connection As New SageX3CloudConnection(connectionString)
Dim cmd As New SageX3CloudCommand("SELECT * FROM Customer", connection)
Dim rdr As SageX3CloudDataReader = cmd.ExecuteReader()
While rdr.Read()
Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("Name"), rdr("Description")))
End While
End Using