<?xml version="1.0"?>
<?xml-stylesheet  href="../aspnetprogram.xsl" type="text/xsl" ?>
<program>
<title>Database To XML Conversion Tool</title>
<author>P.Srikanth</author>
<place>Srikanth Technologies,Vizag</place>
<creationdate>25-Apr-2006</creationdate>
<updationdate>25-Apr-2006</updationdate>
<content>
<![CDATA[

<!-- This programs needs  ASP.NET 2.0 and SQL Server -->

<%@ Page Language="VB" %>
<%@ Import Namespace="System.data.sqlclient" %>
<%@ Import Namespace="System.data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ' check any filename is entered
        If TextBox1.Text.Trim.Length = 0 Then
            Label1.Text = "Enter file name in the textbox."
            Return
        End If
        ' check whether any column is selected
        If CheckBoxList1.SelectedIndex = -1 Then
            Label1.Text = "Select Columns!"
            Return
        End If
        ' get columns
        Dim item As ListItem
        Dim columns As String = ""
        Dim tname As String = DropDownList1.SelectedItem.Text
        For Each item In CheckBoxList1.Items
            If item.Selected Then
                columns &= "," & item.Text
            End If
        Next
        columns = columns.Substring(1)
        Dim con As New SqlConnection("uid=sa;database=pubs")
        Dim da As New SqlDataAdapter("select " & columns & " from " + tname, con)
        Dim ds As New DataSet
        da.Fill(ds, tname)
        ds.WriteXml(Request.MapPath(TextBox1.Text))
        Label1.Text = "Created XML File : " & TextBox1.Text
    End Sub

    Protected Sub btnSelectAll_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim item As ListItem
        For Each item In CheckBoxList1.Items
            item.Selected = True
        Next
    End Sub

   
    Protected Sub btnUnselect_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        CheckBoxList1.ClearSelection()
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body bgcolor="lightgrey">
    <form id="form1" runat="server">
        
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
            SelectCommand="select id,name from sysobjects where xtype='u'"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
            SelectCommand="select name from syscolumns where id = @id">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="id" PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:SqlDataSource>
        <br />
        <h2>
            <span style="color: #000033">Database To XML Conversion Tool&nbsp;</span></h2>
<p></p>
<table>
<tr>
<td bgcolor="whitesmoke">
Select Table :
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
            DataTextField="name" DataValueField="id" Width="135px">
        </asp:DropDownList>
        <p />
        Select Columns
        <br />
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource2"
            DataTextField="name" DataValueField="name">
        </asp:CheckBoxList><br />
    <asp:Button ID="btnSelectAll" runat="server" OnClick="btnSelectAll_Click" Text="Select All" />
    <asp:Button ID="btnUnselect" runat="server" Text="Unselect All" OnClick="btnUnselect_Click"  /><br />
        &nbsp;

</td>
<td>
Enter Target File&nbsp;<br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
    <br />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Create XML" />
    <br />
    <br />
    <asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Bold="True" Font-Size="Medium" ForeColor="Blue"></asp:Label></td>
</tr>
</table>
        <br />
    </form>
</body>
</html>


]]>


</content>
</program>   

