C#完成xml文件的讀取與寫入簡略實例。本站提示廣大學習愛好者:(C#完成xml文件的讀取與寫入簡略實例)文章只能為提供參考,不一定能成為您想要的結果。以下是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#法式設計有所贊助。