How to Insert the Data and Write the XML File

By
In  this tutorial  i will show you,how to  insert the data and write the XML File.There are some steps which are as given below
Step1:-  First open your visual studio and go  File->New Website->Select ASP.NET Empty Website->Select visual C#->press OK.
Now open the Solution Explorer(if not open)->Add New Item->Add Default. aspx page.After that drag and drop the controls from the Toolbox which are as shown below:-


Step2:-   Now open solution Explorer--> Add a XML File  --> make a table First which is as shown below:-


Step3:-    Now Double click on Insert Button and write the following codes (Default. asp x.cs) which are as given below:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {   DataSet ds = new DataSet();
        //read xml file path
        ds.ReadXml(Server.MapPath("~/XMLFile.xml"));
        DataRow dr = ds.Tables[0].NewRow();
        dr[0] = TextBox1.Text;
        dr[1] = TextBox2.Text;
        dr[2] = TextBox3.Text;
        ds.Tables[0].Rows.Add(dr);
        //write the data in XMLFile.xml(file name)
        ds.WriteXml(Server.MapPath("~/XMLFile.xml"));
        Label5.Text = " DATA HAS BEEN SUCCESSFULLY INSERTED";
        Label5.ForeColor = Color.Red;
    }
}
NOTE:-> Here i have added two extra Namespace.
using System.Data;
using System.Drawing;
See it:-

Step4:-  Now Run the Default.aspx page(press F5). you can see as shown below:-


Step5:-Now Filled the required field details and press INSERT Button. You will have shown which is as shown below:-

NOTE-> If any other window is opening -->press YES

Step6:- Now go to the XML File .You can see, data has been sucessfully Inserted.

For More...

  1. Send mail from Asp.Net application free.
  2. Create captcha image.
  3. Threading in c#.
  4. create setup file with database
  5. File handling Real application

I hope this is helpful for you.
To Get the Latest  Free Updates Subscribe
Click below for download whole Application.
                   DOWNLOAD

2 comments:

Powered by Blogger.