
<HTML>
	<HEAD>
		<title>将数据库数据填充到 XML 文件示例</title><% @Import Namespace="System.Data" %>
		<% @Import Namespace="System.Data.SqlClient" %>
		<script language="C#" runat="server">
		
			void Page_Load(object sender, System.EventArgs e)
			{
				// 连接字符串及 SQL 语句
				string ConnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];
				string Sql = "SELECT CustomerID,CompanyName,Country FROM Customers";

				// 连接 SqlConnection 及 SqlDataAdapter 对象
				SqlConnection thisConnection = new SqlConnection(ConnString);
				SqlDataAdapter adapter = new SqlDataAdapter(Sql, thisConnection);

				// 创建 DataSet 对象
				DataSet data = new DataSet();

				// 填充 DataSet
				adapter.Fill(data, "Customers");

				// 将 DataSet 数据其及架构填充到 Xml 文件
				data.WriteXml(Server.MapPath(".") + "\\myXml.xml", XmlWriteMode.WriteSchema);
				
				// 提示填充是否成功
				Label1.Text = "填充到XML文件成功";
			}
			
		</script>
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>将数据库数据填充到XML文件示例</h3>
			<P>
				<asp:Label id="Label1" runat="server">Label</asp:Label></P>
		</form>
	</body>
</HTML>
