using System;
using System.Data;// for ADO.Net
using System.Data.SQL; // for SQL Server managed provider
using System.IO; // for FileStream class
using System.Text; // for StringBuilder class
public class WriteXML
{ public static void Main()
{ // Build a connection
SQLConnection myConn =
new SQLConnection
("server=yourServerName;uid=yourUserId;pwd=yourPassword;database=Northwind");
// Build the SQL string
StringBuilder mySql = new StringBuilder("SELECT ProductId, ");
mySql.Append("ProductName, UnitPrice ");
mySql.Append("FROM Products ");
mySql.Append("WHERE UnitPrice < 10.00");
mySql.Append("ORDER BY UnitPrice ");
Console.WriteLine(mySql); // Build the DataSet Command object
SQLDataSetCommand myCmd = new SQLDataSetCommand
(mySql.ToString(), myConn);
// Build the DataSet
DataSet myDs = new DataSet(); // Fill the DataSet with a dataset table named "Products"
myCmd.FillDataSet(myDs, "Products"); // Get a FileStream object
FileStream myFs =
new FileStream
("myXmlData.xml",FileMode.OpenOrCreate,FileAccess.Write); // Use the WriteXml method of DataSet object to write an XML file from the DataSet
myDs.WriteXml(myFs);
myFs.Close();
Console.WriteLine("File Written");
}
}
using System.Data;// for ADO.Net
using System.Data.SQL; // for SQL Server managed provider
using System.IO; // for FileStream class
using System.Text; // for StringBuilder class
public class WriteXML
{ public static void Main()
{ // Build a connection
SQLConnection myConn =
new SQLConnection
("server=yourServerName;uid=yourUserId;pwd=yourPassword;database=Northwind");
// Build the SQL string
StringBuilder mySql = new StringBuilder("SELECT ProductId, ");
mySql.Append("ProductName, UnitPrice ");
mySql.Append("FROM Products ");
mySql.Append("WHERE UnitPrice < 10.00");
mySql.Append("ORDER BY UnitPrice ");
Console.WriteLine(mySql); // Build the DataSet Command object
SQLDataSetCommand myCmd = new SQLDataSetCommand
(mySql.ToString(), myConn);
// Build the DataSet
DataSet myDs = new DataSet(); // Fill the DataSet with a dataset table named "Products"
myCmd.FillDataSet(myDs, "Products"); // Get a FileStream object
FileStream myFs =
new FileStream
("myXmlData.xml",FileMode.OpenOrCreate,FileAccess.Write); // Use the WriteXml method of DataSet object to write an XML file from the DataSet
myDs.WriteXml(myFs);
myFs.Close();
Console.WriteLine("File Written");
}
}
解决方案 »
- C#/C++/VC如何实现获取一个winrar能打开的所有文件格式里面的文件目录
- 帮帮初学者,求导出EXCEL的代码
- c# 如何获取当前已安装程序的列表
- 求助一个VS2005!
- HttpWebRequest 读取网站返回为中文成乱码请指导员
- 怎么样用c# gdi+打开一张图片,并且把图片绘在窗体的中间??
- DirectoryEntry.Properties包括哪些项?
- 问个关于socket的基础问题
- 一个class的object作为方法的参数,在方法内改变object的值,调用该方法后,object值是否改变?请指教
- C#中怎么样可以直接编写一个事件响应程序,象VB一样,而不必手动编写事件响应的声明部分。
- 急:如何替换htm页面中的图片的路径?
- 警告:用金山毒霸2003可能导致vs.net help system工作异常!!!建议勿装金山毒霸2003!!!
插节点,还是增加 节点的属性????
//list 为路径的字符
XmlDocument myDoc = new XmlDocument(); //定义一个XmlDocument对象。
try
{
myDoc.Load(list);
}
catch
{
this.Response.Write("没能加载文件");
this.Response.End();
}
XmlNode root = doc.DocumentElement; //Create a new node.
XmlElement elem = doc.CreateElement("price");
elem.InnerText="19.95"; //Add the node to the document.
root.InsertAfter(elem, root.FirstChild); doc.Save(" test.xml");