ASP.net从数据库中取出数据添加到xml文件中的方法
来源:互联网 发布:数据库第六版pdf网盘 编辑:程序博客网 时间:2024/05/16 18:25
当从数据库里取出数据填充到DataTable时,若使用dt.WriteXml(路径)读出的结果是
<DataTable>
<table>
.
.
</table>
<DataTable>
只是将DataTable直接转换成xml,
应该使用以下的方法:
XElement xmlbookstore = new XElement("bookstore");
for (int i = 0; i < dt.Rows.Count; i++)
{
XElement xmlbook = new XElement("book");
XElement xmltitle = new XElement("title",dt.Rows[i]["title"].ToString());
XElementxmlauthor=newXElement("author",dt.Rows[i]["author"].ToString());
XElement xmlyear = new XElement("year", dt.Rows[i]["year"].ToString());
XElement xmlprice = new XElement("price", dt.Rows[i]["price"].ToString());
xmlbook.Add(xmltitle);
xmlbook.Add(xmlauthor);
xmlbook.Add(xmlyear);
xmlbook.Add(xmlprice);
xmlbookstore.Add(xmlbook);
}
FileStream stream = File.OpenWrite(Server.MapPath("a.xml"));
StreamWriter writer = new StreamWriter(stream);
writer.Write(xmlbookstore.ToString());
writer.Flush();
writer.Dispose();
- ASP.net从数据库中取出数据添加到xml文件中的方法
- ASP.NET从数据库中取出数据添加到xml中方法
- 从数据库中取出数据导入到xml中的方法
- ASP.NET从数据库中取出数据,有数据的复选框为选中
- ASP.NET 从Excel文件导入数据到数据库(笔记)
- [ASP.net]从数据库中读取数据自动生成XML
- ASP.Net 向xml文件中添加数据(insert操作)
- ASP.Net 向xml文件中添加数据(insert操作)
- 从数据库中取出数据,并生成xml文档
- 从数据库中取出数据
- Java从入门到精通——技巧篇之利用dom4j取出XML文件中的数据
- c# 中添加数据到数据库中的三种方法
- c# 中添加数据到数据库中的三种方法 .
- 递归方法读取数据库中的数据,添加到TreeView中
- ASP.NET 从数据库中导出数据
- 利用dom4j取出XML文件中的数据
- 图像保存到XML文件和从XML中取出图像显示
- 图像保存到XML文件和从XML中取出图像显示
- C语言中程序调试和宏使用技巧
- APIO-08-ROADS免费道路
- xml的导入和导出
- 软件项目管理读书体会
- poj 1821 Fence
- ASP.net从数据库中取出数据添加到xml文件中的方法
- APIO-08-DNA
- 数据显示:中国2100万iOS用户多分布在一线城市
- KMP模式匹配算法
- ASP.NET从数据库中取出数据添加到xml中方法
- 迭代创建文件夹
- 『随感。』:生活琐事
- 跟我一起写Makefile
- 苹果再上诉申请禁售三星产品 三星称几乎不可能