Saturday, August 11, 2018

How to connect XML in asp.net


XML  DATABASE  IN ASP.NET
Go to website->add new item -> XML
<?xml version="1.0" encoding="utf-8"?>

<personal>

  <entry name="ram" class="mca" city="jabalpur"> its a  best   student </entry>
  <entry name="FS" class="SDF" city="SDF">SDF</entry>
  <entry name="anoop" class="mca" city="bhopal">best debugger</entry>

</personal>


protected void Button2_Click(object sender, EventArgs e)
    {
          // step  1  open  xml  connect 

        XmlDocument d1 = new XmlDocument();
        d1.Load(Server.MapPath("stu.xml"));
        XmlNode n1 = d1.DocumentElement.FirstChild;


        // step  2 :  populate  the   element 
        XmlElement e1 = d1.CreateElement("entry");


        //bind  all attribute  in text  box  or  other
        e1.SetAttribute("name", Server.HtmlEncode(TextBox5.Text));
        e1.SetAttribute("class", Server.HtmlEncode(TextBox6.Text));
        e1.SetAttribute("city", Server.HtmlEncode(TextBox7.Text));
        e1.InnerText = Server.HtmlEncode(TextBox8.Text);
       
        //save   xml  dat   in  stu
        d1.DocumentElement.InsertAfter(e1, n1);
        d1.Save(Server.MapPath("stu.xml"));

    }

DISPLAY  XML DATABASE

protected void Button3_Click(object sender, EventArgs e)
    {
        XmlTextReader r1 = new XmlTextReader(Server.MapPath("stu.xml"));

        DataSet ds = new DataSet();

        ds.ReadXml(r1);

        r1.Close();


        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();


    }




No comments:

Post a Comment

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...