自打数据库的DataTable的记录集取出来,写及一个XML文件中错过。

XML 1XML 2Code
 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();

            //XML 3XML 4

            write.WriteEndElement();
        }

        write.WriteEndElement();
        write.WriteEndDocument();
        write.Flush();
        write.Close();
    }

文件格式:.wmv;大小:12,567KB;长度XML:00:19:00。
下载地址:http://download.cnblogs.com/insus/ASPDOTNET/CreateXMLFile.zip

 

相关文章

网站地图xml地图