来自 新葡8455编程 2020-04-30 21:30 的文章
当前位置: 新葡棋牌京官网app > 新葡8455编程 > 正文

MSSQL带你轻松接触数据库生成xml的两个方法

核心提示:第一个示例方法:1 SqlConnection conn = new SqlConnection

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

1 SqlConnection conn = new SqlConnection();

2 conn.ConnectionString = Server=127.0.0.1;User

ID=sa;Password=fdahgdrethj31313210212121;

Database=northwind;Persist Security Info=True;

3 conn.Open();

本文由新葡棋牌京官网app发布于新葡8455编程,转载请注明出处:MSSQL带你轻松接触数据库生成xml的两个方法

关键词: