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

XML
多级联动下拉选择框,动态获取下一级
利用XMLSerializer将对象串行化到XML
用XML和XSL来生成动态页面
XML的简单读取与写入
手把手教你制作Google Sitemap
用XsltArgumentList实现xsl的参数调用
将一个图片以二进制值的形式存入Xml文件中
将图片读入到Dom中,并将其存为xml文件
WML初级教程之从实际应用中了解WML
利用XMLBean轻轻松松读写XML
.NET中书写XML的一种简单方法
实例简析XPath串函数和XSLT
在XPath查询中指定轴(转自MSSQL手册)
使用带批注的 XDR 架构创建 XML 视图
使用 XML 模板 (MSSQL手册)
新兴XML处理方法VTD-XML介绍
利用XML实现通用WEB报表打印实际使用中的例子
从XML中读取数据到内存的实例
Xml_javascript分页
创建带有关联的 XML 架构的 XML 文件 && 从 XML 文件创建 XML 架构

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 73 ::
收藏到网摘: 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 }