|
WritingAndGeneratingXml.aspx
<% @ Page Language ="VB" AutoEventWireup ="false" CodeFile ="Example15.aspx.vb" Inherits ="Example15" %>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server">
</ head >
< body >
< form id ="form1" runat ="server">
< div >
< asp : Button ID ="Button1" runat ="server" Text ="Writing XML DOC!!!" />
< asp : Button ID ="Button2" runat ="server" Text ="Save XML in a File!!" /></ div >
</ form >
</ body >
</ html >
WritingAndGeneratingXml.aspx.vb
Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class Example15 Inherits System.Web.UI.Page
//This will display the dataset in the form of XML on the Browser
Protected Sub Button1_Click( ByVal sender As Object , ByVal e As System.EventArgs) Handles Button1.Click
Dim con As SqlConnection
Dim ada As SqlDataAdapter
Dim dst As DataSet
Dim strXML As String
con = New SqlConnection( "Data Source=localhost;Initial catalog=Northwind;UID=sa;pwd=sa" )
ada = New SqlDataAdapter( "select CategoryId,CategoryName from Categories" , con)
dst = New DataSet
con.Open()
ada.Fill(dst, "Categories" )
con.Close()
strXML = dst.GetXml()
Response.Write( "<pre>" & Server.HtmlEncode(strXML) & "</pre>" )
End Sub
Protected Sub Button2_Click( ByVal sender As Object , ByVal e As System.EventArgs) Handles Button2.Click
Dim con As SqlConnection
Dim ada As SqlDataAdapter
Dim dst As DataSet
con = New SqlConnection( "Data Source=localhost;Initial catalog=Northwind;UID=sa;pwd=sa" )
ada = New SqlDataAdapter( "select * from Products" , con)
dst = New DataSet
con.Open()
ada.Fill(dst, "Products" )
con.Close()
dst.WriteXml( "G:\WebProjects2005\SourceDemo\XMLFILE\ProductXml.xml" )
Response.Write(" Save ProductXml File Successfully!!!" )
End Sub
End Class
|