国庆快乐,有一问题还请大伙帮忙?
用代码以下生成的记录怎么总是有二条,为什么?
string xmlFilename = "myXmlDocument.xml";
DataSet newDataSet = new DataSet("New DataSet");
// Read the XML document back in.
// Create new FileStream to read schema with.
System.IO.FileStream fsReadXml = new System.IO.FileStream(Server.MapPath(xmlFilename), System.IO.FileMode.Open);
// Create an XmlTextReader to read the file.
System.Xml.XmlTextReader myXmlReader = new System.Xml.XmlTextReader(fsReadXml);
// Read the XML document into the DataSet.
newDataSet.ReadXml(myXmlReader);
// Close the XmlTextReader
myXmlReader.Close();
DataRow newRow;
newRow = newDataSet.Tables[0].NewRow();
newRow["Name"]=Name.Text;
newRow["Email"]=Email.Text;
newDataSet.Tables[0].Rows.Add(newRow);
System.IO.FileStream fsWriteXml = new System.IO.FileStream(Server.MapPath(xmlFilename), System.IO.FileMode.OpenOrCreate);
System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(fsWriteXml, System.Text.Encoding.Unicode);
newDataSet.WriteXml(xmlWriter);
fsWriteXml.Close();