ASP.Net/XML/Database to XML — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:30, 26 мая 2010
Save data from database to xml
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim strConnection As String
Dim strSQL As String
Dim objDataSet As New DataSet()
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapter
" set the connection and query details
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & Server.MapPath("Northwind.mdb")
strSQL = "SELECT FirstName, LastName FROM Employees;"
" open the connection and set the command
objConnection = New OledbConnection(strConnection)
objAdapter = New OledbDataAdapter(strSQL, objConnection)
" fill the dataset with the data
objAdapter.Fill(objDataSet, "Employees")
objDataSet.WriteXml(Server.MapPath("Employees.xml"))
Response.Write("<a href="Employees.xml">View XML file</a>")
End Sub
</script>
Save query result data from database to XML file
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim strConnection As String
Dim strSQL As String
Dim objDataSet As New DataSet()
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapter
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source="+MapPath("EmployeeDatabase.mdb")
strSQL = "SELECT FirstName, LastName FROM Employee;"
objConnection = New OledbConnection(strConnection)
objAdapter = New OledbDataAdapter(strSQL, objConnection)
objAdapter.Fill(objDataSet, "Employees")
objDataSet.WriteXml(Server.MapPath("Employee2.xml"))
Response.Write("XML File Generated")
End Sub
</script>
<A href="http://www.nfex.ru/Code/ASPDownload/EmployeeDatabase.zip">EmployeeDatabase.zip( 10 k)</a>
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>
<A href="http://www.nfex.ru/Code/ASPDownload/Northwind.zip">Northwind.zip( 736 k)</a>