Hi Matt,
You can connect to the database, retrieve the data and construct a
stringbuilder formatted based on csv format, and then right it to the
client. I have a simlar example which retrieve data and display it in Excel
format. Please see if it is useful to you?
private void Page_Load(object sender, System.EventArgs e)
{
Response.ContentType = "application/ms-excel";
Response.AddHeader("Content-Disposition", "inline;filename=rawdata.xls");
Response.Buffer = true;
this.EnableViewState = false;
SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSettings["conn"]); // replace with
your connection string
conn.Open();
string sql = "SELECT * FROM rawdata ORDER BY createdate"; // replace
with your sql statement
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables[0];
dg.AllowPaging = false;
dg.DataBind();
dg.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
conn.Close();
}
Regards,
Jack Li
MVP (ASP.NET)