如何将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