954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Example of Inserting and Retrieving data from xml file

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

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;
			}
hanusoft
Newbie Poster
6 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

hello hanusoft,
i have been trying to insert data from my project which i m doing using asp.net and the language is c#.
i have tried ur code.
it has given 4 errors.
Error 1

'ASP.default_aspx.GetTypeHashCode()': no suitable method found to override
the file where the error occurs

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\firstasp\2e57531e\
3fdfeee\App_Web_komf0cr-.2.cs

the rest of the problem occurs in the same file.
can u tell me what is the wrong with here?

monjuri
Newbie Poster
6 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

are you using a BasePage or override any methods manually ?

Hosam Kamel
Newbie Poster
12 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 

Hi I am creating a Windows Application in C#, for which I am using xml files. I want to insert data into xml file as xml node when I user enter his information into Multi line textboxes. I have tried your above code for asp in my Win forms, but unable to make it work. So please assist me for Windows App

Umaid
Newbie Poster
4 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You