Convert XML to Dataset in - C#

Recently client sends me a XML file and he wanted to filter some records. I discussed this problem with one of my friend he told me that you can use DataSet. After some research, I found that we can load the string into DataSet. In this post, I will show you how to load XML string into DataSet and display the record on the web page.

Convert XML to Dataset in - C#

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
   <title>Untitled Page</title>
   <form id="form1" runat="server">
           <asp:GridView ID="GridView1" runat="server">
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default3 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        string xmldata = "<DocumentElement>" +
             "<OutLier>" +
             "<Name>1</Name>" +
             "<DOB>19800101</DOB>" +
             "<State>GG</State>" +
             " <ID>12345</ID> " +
             " <SIG>Y</SIG> " +
             "</OutLier>" +
              "<OutLier>" +
             "<Name>2</Name>" +
             "<DOB>19800101</DOB>" +
             "<State>GG</State>" +
              " <ID>1325</ID> " +
             " <SIG>Y</SIG> " +
             "</OutLier>" +

            DataSet ds = new DataSet();
            System.IO.StringReader sr = new System.IO.StringReader(xmldata);
            GridView1.DataSource = ds;

        catch (ArgumentNullException ex)


Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads