Write data from database to XML file and view the result in C#
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="c#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
String strConnection, strSQL;
DataSet objDataSet = new DataSet();
OleDbConnection objConnection = null;
OleDbDataAdapter objAdapter = null;
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; ";
strConnection += "Data Source=" + Server.MapPath("Northwind.mdb");
strSQL = "SELECT FirstName, LastName FROM Employees;";
objConnection = new OleDbConnection(strConnection);
objAdapter = new OleDbDataAdapter(strSQL, objConnection);
objAdapter.Fill(objDataSet, "Employees");
objDataSet.WriteXml(Server.MapPath("Employees2.xml"));
Response.Write("<a href='Employees2.xml'>View XML file</a>");
}
</script>
Northwind.zip( 736 k)Related examples in the same category