最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442

数据库生成xml的简单方法

日期:11-10    来源:中国设计秀    作者:cnwebshow.com

 xl1中国设计秀

第一个示例方法:xl1中国设计秀

1 SqlConnection conn = new SqlConnection();xl1中国设计秀

2 conn.ConnectionString = "Server=127.0.0.1;Userxl1中国设计秀

ID=sa;Password=fdahgdrethj31313210212121;xl1中国设计秀

Database=northwind;Persist Security Info=True";xl1中国设计秀

3 conn.Open();xl1中国设计秀

4 SqlDataAdapter da = new SqlDataAdapter("select * from 表", conn);xl1中国设计秀

5 SqlCommandBuilder thisBulder = new SqlCommandBuilder(da);xl1中国设计秀

6 DataSet ds = new DataSet();xl1中国设计秀

7 da.Fill(ds);xl1中国设计秀

8 ds.WriteXml(@"C:temp.xml");xl1中国设计秀

第二个示例方法:xl1中国设计秀

1 private void WriteXmlToFile(DataSet thisDataSet)xl1中国设计秀
2 {xl1中国设计秀
3 if (thisDataSet == null) { return; }xl1中国设计秀
4 // Create a file name to write to.xl1中国设计秀
5 string filename = "myXmlDoc.xml";xl1中国设计秀
6 // Create the FileStream to write with.xl1中国设计秀
7 System.IO.FileStream myFileStream = new System.IO.FileStreamxl1中国设计秀
8 (filename, System.IO.FileMode.Create);xl1中国设计秀
9 // Create an XmlTextWriter with the fileStream.xl1中国设计秀
10 System.Xml.XmlTextWriter myXmlWriter =xl1中国设计秀
11 new System.Xml.XmlTextWriterxl1中国设计秀
(myFileStream, System.Text.Encoding.Unicode);xl1中国设计秀
12 // Write to the file with the WriteXml method.xl1中国设计秀
13 thisDataSet.WriteXml(myXmlWriter);xl1中国设计秀
14 myXmlWriter.Close();xl1中国设计秀
15 }xl1中国设计秀