1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

example of Inserting and Retrieving data from xml file

Discussion in 'Web Development' started by hanusoft, Sep 25, 2007.

  1. hanusoft

    hanusoft New Member

    Joined:
    Sep 3, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    This is an example of Inserting and Retrieving data from xml file.

    Code:
    private void Page_Load(object sender, System.EventArgs e)
    {
    	// Put user code to initialize the page here
    	
    	if(!IsPostBack)
    	{
    		BindGrid();
    	}
    }
    
    
    private void BindGrid()
    {
    	ds = new DataSet();
    	try
    	{
    		ds.ReadXml(@"c:\inetpub\wwwroot\WebApplication10\XMLFile1.xml");
    		DataGrid1.DataSource = ds;
    		DataGrid1.DataBind();
    	}
    	catch(Exception ex)
    	{
    		throw ex;
    	}
    }
    
    
    
    
    private void Button1_Click(object sender, System.EventArgs e)
    {
    	ds = new DataSet();
    	try
    	{
    		ds.ReadXml(@"c:\inetpub\wwwroot\WebApplication10\XMLFile1.xml");
    		DataRow row = ds.Tables[0].NewRow();
    		row["name"]=txtName.Text;
    		row["fathersname"]=txtFName.Text;
    		row["address"]=txtAddress.Text;
    		ds.Tables[0].Rows.Add(row);
    		ds.WriteXml(@"c:\inetpub\wwwroot\WebApplication10\XMLFile1.xml");
    		txtAddress.Text="";
    		txtFName.Text="";
    		txtName.Text ="";
    		BindGrid();
    	}
    	catch(Exception ex)
    	{
    		throw ex;
    	}
    }
     
    Last edited by a moderator: Sep 25, 2007

Share This Page