当前位置:开发者网络 >> 技术教程 >> .NET教程 >> XML应用 >> 内容
精彩推荐
分类最新教程
分类热点教程
  
根据数据库生成xml二法
作者:未知
日期:2005-08-29
人气:
投稿:(转贴)
来源:未知
字体:
收藏:加入浏览器收藏
以下正文:
SqlConnection conn = new SqlConnection();
      conn.ConnectionString 
= "Server=127.0.0.1;User ID=sa;Password=fdahgdrethj31313210212121;Database=northwind;Persist Security Info=True";
      conn.Open();
      SqlDataAdapter da 
= new SqlDataAdapter("select * from 表", conn);
      SqlCommandBuilder thisBulder 
= new SqlCommandBuilder(da);
      DataSet ds 
= new DataSet();
      da.Fill(ds);
      ds.WriteXml(
@"C:\temp.xml");
==============================================================================
private void WriteXmlToFile(DataSet thisDataSet) {
    
if (thisDataSet == nullreturn; }
    
// Create a file name to write to.
    string filename = "myXmlDoc.xml";
    
// Create the FileStream to write with.
    System.IO.FileStream myFileStream = new System.IO.FileStream
       (filename, System.IO.FileMode.Create);
    
// Create an XmlTextWriter with the fileStream.
    System.Xml.XmlTextWriter myXmlWriter = 
       
new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
    
// Write to the file with the WriteXml method.
    thisDataSet.WriteXml(myXmlWriter);   
    myXmlWriter.Close();
 }

相关文章: