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 visualC#->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:-
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:-
NOTE-> If any other window is opening -->press YES
Step6:- Now go to the XML File .You can see, data has been sucessfully Inserted.
Step1:- First open your visual studio and go File->New Website->Select ASP.NET Empty Website->Select visualC#->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:-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| 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; }} |
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:-
Step6:- Now go to the XML File .You can see, data has been sucessfully Inserted.
0 Comments
Post a Comment