科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道根据数据库生成xml二法

根据数据库生成xml二法

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

  SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Server=127.0.0.1;User ID=sa;Password=fdahgdrethj31

作者:中国IT实验室 来源:中国IT实验室 2007年9月28日

关键字: XML DotNet 编程

  • 评论
  • 分享微博
  • 分享邮件
  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 == null) { return; }
    // 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();
}

查看本文来源

    • 评论
    • 分享微博
    • 分享邮件