把表中的数据select出来fill到dataset,再用dataset.getxml()就可以得到xml字符串了,然后再写到文件中去
或者用
select * from table for xml 
来得到表的xml字符串再写到文件中去

解决方案 »

  1.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=F3EB8683-DB3C-4460-ADB7-7C5C12348A11
      

  2.   

    谢谢楼上2位,我这样写:string strCon = "Integrated Security=SSPI;Server=(local);Database=Test";
    SqlConnection conn = new SqlConnection(strCon);
    conn.Open();
    string sql = "SELECT * FROM Field";
    SqlCommand Cmd = new SqlCommand(sql,conn);
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter(Cmd);
    da.Fill(ds);
    ds.GetXml();
    string filename = "test.xml";
    FileStream fs = new FileStream(filename,FileMode.Create);
    XmlTextWriter writer = new XmlTextWriter(fs, System.Text.Encoding.Unicode);
    ds.WriteXml(writer);出错:对路径“c:\windows\system32\inetsrv\test.xml”的访问被拒绝。
    WHY?