【发布时间】:2012-01-13 02:47:59
【问题描述】:
我已经被这个问题困扰了几个小时,似乎无法弄清楚,所以我在这里问:)
好的,我有这个功能:
private void XmlDump()
{
XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
XElement rootElement = new XElement("dump");
rootElement.Add(TableToX("Support"));
string connectionString = ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
string sql = "select * from support";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet("Test");
da.Fill(ds, "support");
// Convert dataset to XML here
var docresult = // Converted XML
Response.Write(docResult);
Response.ContentType = "text/xml; charset=utf-8";
Response.AddHeader("Content-Disposition", "attachment; filename=test.xml");
Response.End();
}
我一直在尝试各种不同的方法,但总是出错,所以我将如何将 DataSet 转换为 XML 部分留空。
另外,这个查询包含带有特殊字符的列。
【问题讨论】:
标签: c# asp.net xml xml-serialization dataset