How to use GetXml() method in asp.net xml ADO.NET

XML ADO.NET GetXml() Method
GetXmlMethod.aspx

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Web.Configuration" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void Button1_Click(object sender, System.EventArgs e)
    {
        string connString = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
        string sql = "Select Top 2 ProductID, ProductName, QuantityPerUnit, UnitPrice from Products";
        DataSet productsDataSet = new DataSet();
        SqlConnection conn = new SqlConnection(connString);
        using (conn)
        {
            SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
            adapter.Fill(productsDataSet);
            GridView1.DataSource = productsDataSet;
            GridView1.DataBind();
        }
        Literal1.Text = Server.HtmlEncode(productsDataSet.GetXml());
        Label1.Text = "XML from DataSet";
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>XML GetXml() - How to use GetXml() method in asp.net xml ADO.NET</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:DarkBlue; font-style:italic;">XML and ADO.NET Example: How To Use GetXml() Method</h2>
        <hr width="575" align="left" color="DarkBlue" />
        <br />
        <asp:GridView 
            ID="GridView1"
            runat="server"
            BorderColor="Pink"
            ForeColor="HotPink"
            >
        </asp:GridView>
        <br />
        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Bold="true"
            Text=""
            ForeColor="OrangeRed"
            Font-Size="Large"
            Font-Names="Comic Sans MS"
            >
        </asp:Label>
        <br />
        <asp:Literal 
            ID="Literal1"
            runat="server"
            >
        </asp:Literal>
        <br /><br />
        <asp:Button 
            ID="Button1"
            runat="server"
            OnClick="Button1_Click"
            Text="Get XML From DataSet"
            Height="40"
            Font-Bold="true"
            ForeColor="DarkBlue"
            />
    </div>
    </form>
</body>
</html>
Related asp.net example