XmlTextWriter 与XmlWriter
我想把学生信息表的内容通过XmlTextWriter或XmlWriter写入xml文件发现用 XmlWriter 完成不了.系统回报错
只好改用XmlTextWriter 即下面的代码 但是我知道到创建的xml文档放到哪儿
那位知道 告诉我啊,或是还有其他实现办法也告诉我啊
using (XmlTextWriter writer = new XmlTextWriter(new StringWriter(str)))
{
/* writer.WriteStartElement ("学生信息");
writer.WriteElementString("StuId", "幻想曲");
writer.WriteElementString("Name", "Net");
writer.WriteElementString("Sex", "Net");
writer.WriteElementString("Birthday", "19xx:xx:xx");
writer.WriteElementString("Adress", "sds");
writer.WriteElementString("Grade", "99");
writer.WriteEndElement(); */
conn = new SqlConnection("server=LocalHost;integrated security=sspi;database=StudentInformation");
comm=new SqlCommand ("select * from StuInfo",conn);
conn .Open ();
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
writer.WriteStartElement("");
// xw.WriteStartElement("item");
writer.WriteElementString("StuId",dr[0].ToString ());
writer.WriteElementString("Name",dr[1].ToString());
writer.WriteElementString("Sex",dr[2].ToString());
writer.WriteElementString("Birthday",dr[3].ToString());
writer.WriteElementString("Adress",dr[4].ToString());
writer.WriteElementString("Grade",dr[5].ToString());
writer.WriteEndElement();
}