By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,508 Members | 1,856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,508 IT Pros & Developers. It's quick & easy.

Example of Inserting and Retrieving data from xml file

P: 4
This is an example of Inserting and Retrieving data from xml file.


Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2.         {
  3.             // Put user code to initialize the page here
  4.  
  5.             if(!IsPostBack)
  6.             {
  7.                 BindGrid();
  8.             }
  9.         }
  10.  
  11.  
  12. private void BindGrid()
  13.         {
  14.             ds = new DataSet();
  15.             try
  16.             {
  17.                 ds.ReadXml(@"c:\inetpub\wwwroot\WebApplication10\XMLFile1.xml");
  18.                 DataGrid1.DataSource = ds;
  19.                 DataGrid1.DataBind();
  20.             }
  21.             catch(Exception ex)
  22.             {
  23.                 throw ex;
  24.             }
  25.         }
  26.  
  27.  
  28.  
  29.  
  30.     private void Button1_Click(object sender, System.EventArgs e)
  31.         {
  32.             ds = new DataSet();
  33.             try
  34.             {
  35.                 ds.ReadXml(@"c:\inetpub\wwwroot\WebApplication10\XMLFile1.xml");
  36.                 DataRow row = ds.Tables[0].NewRow();
  37.                 row["name"]=txtName.Text;
  38.                 row["fathersname"]=txtFName.Text;
  39.                 row["address"]=txtAddress.Text;
  40.                 ds.Tables[0].Rows.Add(row);
  41.                 ds.WriteXml(@"c:\inetpub\wwwroot\WebApplication10\XMLFile1.xml");
  42.                 txtAddress.Text="";
  43.                 txtFName.Text="";
  44.                 txtName.Text ="";
  45.                 BindGrid();
  46.             }
  47.             catch(Exception ex)
  48.             {
  49.                 throw ex;
  50.             }
Oct 1 '07 #1
Share this Question
Share on Google+
1 Reply


RedSon
Expert 5K+
P: 5,000
The account of member hanusoft has been banned for a period of one week. Cross posting, failure to use code tags and spamming your website are against site rules. Please read the posting guidelines.

-MODERATOR
Nov 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.