如何将DATASET的数据导出到XML文件,并直接下载
转成其他格式可以使用诸如
Dim Temp As String = String.Format("attachment;filename={0}", "Exports.csv")
Response.ClearHeaders()
Response.AppendHeader("Content-disposition", Temp)
Response.Write(Data)
的方法。
XML呢,怎么办?
答案一
yourDataset.writexml(outputString);
答案二
if you want to output dataset as is, try
DataSet1.WriteXml(Response.OutputStream);
otherwise, you need to create Xml in the way you want, then use Response.Write()
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="C#" runat="server">
void Page_Load(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select * from authors",
"server=localhost;database=pubs;uid=sa;pwd=;");
DataSet ds = new DataSet();
da.Fill(ds);
Response.Clear();
Response.ContentType="text/xml";
Response.AddHeader("Content-Disposition", "attachment; filename=TestXml.xml");
ds.WriteXml(Response.OutputStream);
Response.End();
}
</script>
摘自:如何将DATASET
本文介绍了一种将DATASET中的数据导出为XML文件并直接下载的方法。具体步骤包括设置HTTP响应头、指定文件类型及名称,最后通过WriteXml方法输出数据集到HTTP输出流中。
707

被折叠的 条评论
为什么被折叠?



