Csharp/CSharp Tutorial/XML/XmlDataDocument — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:31, 26 мая 2010
Load XmlDocument Sample
using System;
using System.IO;
using System.Xml;
public class MainClass
{
public static void Main()
{
try
{
XmlDataDocument myXmlDocument = new XmlDataDocument();
myXmlDocument.Load("Sample.xml");
myXmlDocument.Save(Console.Out);
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e.ToString());
}
}
}
ReadData As Xml
using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Xml;
public class MainClass{
public static void Main(string [] args) {
DataSet dataSet = new DataSet("Product");
SqlConnection connection = new SqlConnection("Initial Catalog=Product; Integrated Security=SSPI; User ID=sa");
string command = "SELECT name, p_date FROM employee";
SqlDataAdapter adapter = new SqlDataAdapter(command, connection);
connection.Open();
adapter.Fill(dataSet, "myEmployee");
connection.Close();
XmlDataDocument doc = new XmlDataDocument(dataSet);
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.Formatting = Formatting.Indented;
doc.WriteTo(writer);
}
}