如何将SQL Server数据库表中的数据存储到xml文件中?可能的 ? [英] How to store data from sql server database table into xml file? possible ?
本文介绍了如何将SQL Server数据库表中的数据存储到xml文件中?可能的 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将数据从sql server数据库表存储到xml文件中?有可能这样做吗?如果是,怎么办?
How to store data from sql server database table into xml file? Is it possible to do that ? if yes how??
推荐答案
将数据读入数据表,并使用DataTable.WriteXml [
Read the data into a DataTable, and use the DataTable.WriteXml[^] method.
DataTable dt = new DataTable("Videos");
using (SqlConnection con = new SqlConnection(GenericData.DBConnection))
{
con.Open();
using (SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Videos", con))
{
da.Fill(dt);
using (StreamWriter sw = new StreamWriter(@"D:\Temp\videos.xml"))
{
dt.WriteXml(sw);
sw.Flush();
}
}
}
[edit]嗯?代码去了哪里? -OriginalGriff [/edit]
[edit]Eh? Where did the code go? - OriginalGriff[/edit]
通用数据"出现错误
名称"GenericData"在当前上下文中不存在吗?我该怎么办?是否有名称空间或相关名称?
I get an error on "Generic Data"
the name "GenericData" doesn''t exist in the current context ? what i shall do ? is there a name space or something related?
这篇关于如何将SQL Server数据库表中的数据存储到xml文件中?可能的 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文