ADO.NET Provider for JSON

Build 24.0.9060

Querying with the DataReader

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

Using the JSONDataReader

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

C#

string connectionString = "DataModel=Relational;URI=C:\people.json";

using (JSONConnection connection = new JSONConnection(connectionString)) {
  JSONCommand cmd = new JSONCommand("SELECT * FROM NorthwindOData", connection);
  
  JSONDataReader rdr = cmd.ExecuteReader();

  while (rdr.Read()) {
    Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["personal.name.first"], rdr["personal.name.last"]));
  }
}

VB.NET

Dim connectionString As String = "DataModel=Relational;URI=C:\people.json"

Using connection As New JSONConnection(connectionString)
  Dim cmd As New JSONCommand("SELECT * FROM NorthwindOData", connection)

  Dim rdr As JSONDataReader = cmd.ExecuteReader()

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

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