本文整理匯總了C#中System.Data.SqlClient.SqlCommand.ExecuteXmlReader方法的典型用法代碼示例。如果您正苦於以下問題:C# SqlCommand.ExecuteXmlReader方法的具體用法?C# SqlCommand.ExecuteXmlReader怎麽用?C# SqlCommand.ExecuteXmlReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.ExecuteXmlReader方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateXMLReader
private static void CreateXMLReader(string queryString,
string connectionString)
{
using (SqlConnection connection = new SqlConnection(
connectionString))
{
connection.Open();
SqlCommand command = new SqlCommand(queryString, connection);
System.Xml.XmlReader reader = command.ExecuteXmlReader();
}
}
示例2: SqlCommand.ExecuteXmlReader()
//引入命名空間
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();
}
}