ASP.Net/ADO.net Database/Database to XML — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 11:51, 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>