ADO.NET Provider for XML

Build 22.0.8462

Querying with the DataReader

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

Using the XMLDataReader

The XMLDataReader retrieves data faster than the XMLDataAdapter because it can retrieve data in pages. As you read data from the XMLDataReader, 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.xml";

using (XMLConnection connection = new XMLConnection(connectionString)) {
  XMLCommand cmd = new XMLCommand("SELECT * FROM NorthwindOData", connection);
  
  XMLDataReader rdr = cmd.ExecuteReader();

  while (rdr.Read()) {
    Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["Email"], rdr["Username"]));
  }
}

VB.NET

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

Using connection As New XMLConnection(connectionString)
  Dim cmd As New XMLCommand("SELECT * FROM NorthwindOData", connection)

  Dim rdr As XMLDataReader = cmd.ExecuteReader()

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

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462