从数据库的DataTable的记录集取出来,写到一个XML文件中去。
Code
void CreateXmlFile(DataTable dataTable, string fileName)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter write = XmlWriter.Create(fileName);
write.WriteStartElement("Sales");
foreach (DataRow dr in dataTable.Rows)
{
write.WriteStartElement("Item");
write.WriteStartElement("SalesId");
write.WriteString(dr["SalesId"].ToString());
write.WriteEndElement();
//
write.WriteEndElement();
}
write.WriteEndElement();
write.WriteEndDocument();
write.Flush();
write.Close();
}
文件格式:.wmv;大小:12,567KB;长度:00:19:00。
下载地址:http://download.cnblogs.com/insus/ASPDOTNET/CreateXMLFile.zip