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");
  }
}

解决方案 »

  1.   

    xml文档中插入数:
      插节点,还是增加 节点的属性????
      //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");