Contents of bxml2v.aspx:
<%@Page Language="VB"%> <%@Import Namespace="System.Data" %> <%@Import Namespace="System.Data.OleDb" %> <%@ import Namespace="System.Data.SqlClient" %> <%@Import Namespace="System.Data.Common" %> <html> <head> </head> <body bgcolor="#ffffff"> <center> <table border="1"> <tr> <td><img src="captsm.gif" /></td> <td valign="center" align="middle" bgcolor="#aaaaaa"> <font face="COMIC SANS MS"><font size="4"><b>Writing an XML file from an SQL Query</b></font></font></td> </tr> </table></center> <div>Connection string: <b><span id="outConnect" runat="server"></span></b></div> <div>SELECT command: <b><span id="outSelect" runat="server"></span></b></div><p /> <div id="outMessage" runat="server"> </div> <script language="VB" runat="server"> Sub Page_Load() Dim strConnect as String ="server=AUCKLAND;uid=gl001;pwd=11111;database=gl001" Dim strSelect as String = "SELECT * FROM glmaster" outSelect.InnerText = strSelect Dim objDataSet As New DataSet Try Dim objConnect as new SqlConnection(strConnect) objConnect.Open() 'create a new OleDbDataAdapter using the connection object and select statement Dim objDataAdapter As New SqlDataAdapter(strSelect, objConnect) 'fill the dataset with data from the DataSetCommand object objDataAdapter.Fill(objDataSet, "glaccounts") Catch objError As Exception 'display error details outMessage.innerHTML = "<b>* Error in Try 1 while accessing data</b>.<br />" _ & objError.Message & "<br />" & objError.Source Exit Sub ' and stop execution End Try 'now we're ready to save the DataSet contents to an XML disk file Try 'use the path to the current virtual application Dim strVirtualPath As String = "glmaster.xml" 'write the data and schema from theSet to an XML document on disk 'must use the Physical path to the file not the Virtual path objDataSet.WriteXML(Request.MapPath(strVirtualPath)) outMessage.innerHTML = "Written file: <b><a href=" & Chr(34) & strVirtualPath _ & Chr(34) & ">" & strVirtualPath & "</a></b><br />" Catch objError As Exception 'display error details outMessage.innerHTML = "<b>* Error in Try 2 while writing disk file</b>.<br />" _ & objError.Message & "<br />" & objError.Source Exit Sub ' and stop execution End Try End Sub </script> </body> </html>
***** end of file *** printed: 79 lines on: 11/23/2009 6:06:35 AM