当前位置: 首页 > 图文教程 > XML家族 > XML > 数据库生成xml的简单方法

XML
通过jQuery在IE6中实现选择器标签
jQuery导航插件轻松控制网页导航设计
WEBJX收集整理XML节点相关知识
XML定制超越传统界限的开放XML
WAP网站建设全攻略教程
历数Firefox2.0对XML处理的改进
使用XML实现多渠道接入网站的构架
百度新闻开放协议XML文档制作方法简述
XML:OpenSearch 应用
XML模式:FIXML和SVG
XML模式:XForms和客户发票
WAP教程(3):WML 格式化
WAP教程(4):WML 链接和图像
WAP教程(5):WML 输入
WAP教程(9):WML 实例
XML入门教程:XML语法
XML入门教程:CSS样式表
XML入门教程:XML名称空间
XML入门教程:属性声明
XML入门教程:实体

XML 中的 数据库生成xml的简单方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 65 ::
收藏到网摘: n/a


第一个示例方法:
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();
4 SqlDataAdapter da = new SqlDataAdapter("select * from 表", conn);
5 SqlCommandBuilder thisBulder = new SqlCommandBuilder(da);
6 DataSet ds = new DataSet();
7 da.Fill(ds);
8 ds.WriteXml(@"C:\temp.xml");
第二个示例方法:
1 private void WriteXmlToFile(DataSet thisDataSet)
2 {
3 if (thisDataSet == null) { return; }
4 // Create a file name to write to.
5 string filename = "myXmlDoc.xml";
6 // Create the FileStream to write with.
7 System.IO.FileStream myFileStream = new System.IO.FileStream
8 (filename, System.IO.FileMode.Create);
9 // Create an XmlTextWriter with the fileStream.
10 System.Xml.XmlTextWriter myXmlWriter =
11 new System.Xml.XmlTextWriter
(myFileStream, System.Text.Encoding.Unicode);
12 // Write to the file with the WriteXml method.
13 thisDataSet.WriteXml(myXmlWriter);
14 myXmlWriter.Close();
15 }