晨风资讯网
新闻资讯网络冲浪网页设计网络编程图形图像数据库网络媒体服务器网络安全网站运营软件教程黑客认证Wap技术
教程搜索
教程搜索:
  首页 > 网络编程 > NET教程 > 正文  

根据数据库生成xml二法
日期:2006-1-19 22:21:44 来源:网络 作者:无名 浏览:

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

上一篇: asp.net生成静态页 下一篇:

Render方法生成静态页

返回列表 打印此页 加入收藏 资讯论坛 关闭窗口 点击复制本页地址,发送给QQ/MSN好友
关于我们 - 联系我们 - 版权声明 - 帮助(?) - 广告服务 - 友情链接 - 服务项目 - 人才招聘
2003-2008 版权所有 © 晨风资讯网 未经授权禁止复制或建立镜像
CopyRight 2003-2008 www.Net118.com,All Rights Reserved.Design By ChenFeng Network Studio