C#实现xml文件的读取与写入 C#实现xml文件的读取与写入简单实例
dyx2010 人气:0想了解C#实现xml文件的读取与写入简单实例的相关内容吗,dyx2010在本文为您仔细讲解C#实现xml文件的读取与写入的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:C#,xml文件,读取,写入,下面大家一起来学习吧。
本文实例讲述了C#实现xml文件的读取与写入方法。分享给大家供大家参考。具体如下:
//DataTable DateSet 都可以用来读取xml数据和写入xml数据 protected voidButton1_Click(object sender, EventArgs e) { DataTabledt = new DataTable("Employee"); DataColumndcID = new DataColumn("ID", typeof(string)); DataColumndcName = new DataColumn("NAME", typeof(string)); DataColumndcAGE = new DataColumn("AGE", typeof(string)); DataColumndcDEPT = new DataColumn("DEPT", typeof(string)); dt.Columns.AddRange(new DataColumn[] {dcID, dcName, dcAGE, dcDEPT }); DataRowdr = dt.NewRow(); dr["ID"]= "3"; dr["NAME"]= "chen"; dr["AGE"]= "21"; dr["DEPT"]= "技术部"; dt.Rows.Add(dr); DataSetds2 = new DataSet(); ds2.Tables.Add(dt); DataSetds = new DataSet(); ds.ReadXml(Server.MapPath("Employee.xml")); ds.Merge(ds2);//合并数据 ds.WriteXml(Server.MapPath("Employee.xml")); Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('写入成功')",true); } protected voidButton2_Click(object sender, EventArgs e) { DataSetds = new DataSet(); ds.ReadXml(Server.MapPath("Employee.xml")); GridView1.DataSource = ds; GridView1.DataBind(); }
希望本文所述对大家的C#程序设计有所帮助。
加载全部内容