添加
DataSet data = new DataSet(); data.ReadXml(Server.MapPath("Employee.xml")); DataTable dt = data.Tables[0]; DataRow drow = dt.NewRow(); drow["EmployeeID"] = TextBox1.Text; drow["Name"] = TextBox2.Text; drow["Education"] = TextBox3.Text; drow["Age"] = TextBox4.Text; dt.Rows.Add(drow); dt.AcceptChanges(); data.AcceptChanges(); data.WriteXml(Server .MapPath ("Employee.xml")); Binder();
删除
DataSet data = new DataSet(); data.ReadXml(Server.MapPath("Employee.xml")); if (data.Tables[0].Rows.Count > 0) { for (int i = 0; i < data.Tables[0].Rows.Count; i++) { if (data.Tables[0].Rows[i]["EmployeeID"].ToString().Trim() == TextBox1.Text.ToString().Trim()) { data.Tables[0].Rows[i]["EmployeeID"] = TextBox1.Text; data.Tables[0].Rows[i]["Name"] = TextBox2.Text; data.Tables[0].Rows[i]["Education"] = TextBox3.Text; data.Tables[0].Rows[i]["Age"] = TextBox4.Text; } } data.AcceptChanges(); data.WriteXml(Server.MapPath("Employee.xml")); } Binder();
修改
DataSet data = new DataSet(); data.ReadXml(Server.MapPath("Employee.xml")); if (data.Tables[0].Rows.Count > 0) { for (int i = 0; i < data.Tables[0].Rows.Count; i++) { if (data.Tables[0].Rows[i]["EmployeeID"].ToString().Trim() == TextBox1.Text.ToString().Trim()) { data.Tables[0].Rows[i].Delete(); } } data.AcceptChanges(); data.WriteXml(Server.MapPath("Employee.xml")); } Binder();