I have a project which should include a download function whereby when the user press the download button, the contents of the SQL Server table will be downloaded as a csv file.

Is there any way I can do this?

The contents of the table called `Characters` will be downloaded as a csv file. What I know is that I have use the query `Select* from Characters`, but I do not know how to implement it.

```
        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);
        }

```