using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

namespace WriteToXML
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string ConStr = "server=.;DataBase=XmlDataBase;user id=sa;password=123";
            SqlConnection Con = new SqlConnection(ConStr);
            //打开数据连接对象
            Con.Open();
            //创建数据适配器对象
            SqlDataAdapter DA = new SqlDataAdapter("select * from NewsInfo",Con);
            DataSet Ds = new DataSet();
            //填充数据到数据集
            DA.Fill(Ds,"TableNewsInfo");
            //写入数据到NewsInfo.xml文件中
            Ds.WriteXml(Server.MapPath("NewsInfo.xml"));
            //关闭连接
            Con.Close();
            Con = null;
        }
    }
}
