热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> XML编程>>正文内容

读取数据库中的数据生成xml的两个方法

发布时间:2008年12月08日点击数: 未知
第一个示例方法:
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();
}

本站热点业务

更多模板/案例展示

热门推荐

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作