C#实现xml文件的读取与写入简单实例
程序员文章站
2023-12-06 12:14:58
本文实例讲述了c#实现xml文件的读取与写入方法。分享给大家供大家参考。具体如下:
//datatable dateset 都可以用来读取xml数据和写入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#程序设计有所帮助。