我有一個應該包含下載功能的項目,當用戶按下下載按鈕時,SQL Server表格的內容將作爲csv文件下載。下載SQL Server表的內容,並將其內容放入CSV文件中?
有什麼辦法可以做到這一點?
表格名爲Characters
的內容將作爲csv文件下載。我知道的是,我使用查詢Select* from Characters
,但我不知道如何實現它。
protected void btnDownload_Click(object sender, EventArgs e)
{
string fileName = string.Empty;
string filepath = Request.MapPath("~/Uploads");// this needs to be changed with the SQL query, but I do not know how to implement it
string downloadFileName = "Attendance.zip";
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=" + downloadFileName);
using (ZipFile zip = new ZipFile())
{
foreach (GridView row in gvFiles.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkSelect");
if (cb != null && cb.Checked)
{
fileName = (row.FindControl("lblFileName") as Label).Text;
zip.AddFile(Server.MapPath(Path.Combine(filepath, fileName)), "");
}
}
zip.Save(Response.OutputStream);
}
我正在使用SQL Server 2008 – Mark20