Generating XML files from SQL Database

posted by Scudyen date: Thursday, May 22, 2008 category: ASP.NET
  Featured Story | Printable View | Email It | Comments | Write Comment

 

Before you continue to write your own aspx file, check your directory write permission. I have used Northwind sample database. We will write some of data from Employees table to XML file.

copy & paste this code to a page :

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.XML" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<script language="VB" runat="server">

Sub Page_Load(Source as Object, E as EventArgs)

Dim strCon as string = "Server=127.0.0.1;uid=sa;pwd=;Database=Northwind;"
Dim strSQL as string = "Select EmployeeID, FirstName, LastName, Address, City, PostalCode, Country from Employees 
order by EmployeeID desc"
Dim objDataSet as New DataSet()
Dim objCon as SQLConnection
Dim objAdapter as SQLDataAdapter

objCon = New SQLConnection(strCon)
objAdapter = New SQLDataAdapter(strSQL, objCon)

objAdapter.Fill(objDataSet, "Empls")

objDataSet.WriteXml(Server.MapPath("emp_xml_file.xml"))
message.text = "<a href=emp_xml_file.xml>Check your XML file</a>"

end sub
</script>
<html>
<head>
<title>Write to XML file</title>
</head>
<body>

<asp:label id="message" runat="server" />
</body>
</html>

 


Custom Search



Gazatem Technologies Active News Manager


page counter

Listed with 411asp.net
Listed with 4aspin.com
PHP, ASP, .NET, JSP Resources, Reviews