Querying with the DataReader
The ADO.NET Provider for CData Connect implements two ADO.NET interfaces you can use to retrieve data from CData Connect: ConnectDataAdapter and ConnectDataReader objects. Whereas ConnectDataAdapter objects retrieve a single result set of all the data that matches a query, ConnectDataReader objects fetch data in subset increments as needed.
Using the ConnectDataReader
The ConnectDataReader retrieves data faster than the ConnectDataAdapter because it can retrieve data in pages. As you read data from the ConnectDataReader, 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 = "AuthScheme=basic;URL=http://hostname:port/rest.rsc;User=my_user;Password=my_password;"; using (ConnectConnection connection = new ConnectConnection(connectionString)) { ConnectCommand cmd = new ConnectCommand("SELECT * FROM Orders", connection); ConnectDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["ShipName"], rdr["ShipCity"])); } }
VB.NET
Dim connectionString As String = "AuthScheme=basic;URL=http://hostname:port/rest.rsc;User=my_user;Password=my_password;" Using connection As New ConnectConnection(connectionString) Dim cmd As New ConnectCommand("SELECT * FROM Orders", connection) Dim rdr As ConnectDataReader = cmd.ExecuteReader() While rdr.Read() Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("ShipName"), rdr("ShipCity"))) End While End Using