XmlReader.ReadOuterXml() : XmlReader « System.Xml « C# / C Sharp by API






XmlReader.ReadOuterXml()

  

using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;

class ExecuteXmlReader {
    public static void Main() {
        SqlConnection mySqlConnection = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=sa");
        SqlCommand mySqlCommand = mySqlConnection.CreateCommand();

        mySqlCommand.CommandText =
          "SELECT TOP 5 ProductID, ProductName, UnitPrice " +
          "FROM Products " +
          "ORDER BY ProductID " +
          "FOR XML AUTO";

        mySqlConnection.Open();
        XmlReader myXmlReader = mySqlCommand.ExecuteXmlReader();
        myXmlReader.Read();
        while (!myXmlReader.EOF) {
            Console.WriteLine(myXmlReader.ReadOuterXml());
        }

        myXmlReader.Close();
        mySqlConnection.Close();
    }
}

   
    
  








Related examples in the same category

1.XmlReader.EOF
2.XmlReader.Read()
3.XmlReader.ReadElementContentAsString
4.XmlReader.ReadToFollowing