How to: Generate XML file from database table
来源:互联网 发布:mac游戏 双月 编辑:程序博客网 时间:2024/05/29 03:49
In this article, I am going to show how we can generate a XML file from our Sql Server database. I am going to explain this task with a simple example.
The default.aspx.cs code is:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
string XMLFileName = "D:/XmlFileFromDataBaseData";
string connString = "Data Source=Local; Initial Catalog=northwind; Uid=sa; pwd=";
string Query = "select * from Employees";
XMLGenarate(connString, Query, XMLFileName);
Response.Write(XMLFileName);
}
public void XMLGenarate(string connstring, string Query, string FileName)
{
string XMLFileName = FileName;
con = new SqlConnection(connstring);
da.SelectCommand = new SqlCommand(Query, con);
da.Fill(ds);
FileStream fs = null;
fs = new FileStream(XMLFileName + ".xml", FileMode.OpenOrCreate, FileAccess.Write);
ds.WriteXml(fs);
fs.Close();
}
}
Here in this application, I am using Employees table of northwind DataBase. The location for generated XML file is "D:/". When user run the application then we can see the XML file has been generated. The output of the XML file will look something like this:
- How to: Generate XML file from database table
- How to generate dot file from IDA's GDL format
- how to generate pb file from ckpt files?
- How to generate EOF from keyboard
- How to export class from xml schema file
- How to transform a pdf file from database@server side to client ?
- How to convert CSV into Database Table?
- How to Create/Drop Database, Table
- How do I upload or download XML to/from a database
- How to transfer the data from CSV file to Oracle database use the PL/SQL developer tool
- How to Generate Hibernate Pojo Classes from DB Tables
- How to generate UML Diagrams from Java code in Eclipse
- How to generate a local image from openstack
- How to generate pojo from json schema by maven
- How To Generate An XML File As A Target Datastore Using ODI In An Integration Interface ? [ID 454268
- How to use freetts create/generate a wave file
- How to generate an AR debug log file
- How to generate an AP debug log file
- java 收发邮件
- [2011.8.24乔布斯辞职]IT巨头的青春岁月:史蒂文·乔布斯老照片
- 基础内容
- dumpsys的过滤器
- showModalDialog和showModelessDialog使用心得
- How to: Generate XML file from database table
- 6410设备启动方式分析
- OpenGL学习笔记:二次曲面--gluQuadric
- dedecms 最新漏洞 利用mytag_js上传文件
- 游标的使用方法
- 6410寄存器控制GPIO点亮LED
- 关于Ibatis ORA-00907: missing right parenthesis
- 用C#实现HTTP协议下的多线程文件传输
- 云计算行业分析PPT