once you have your datatable dt
here you should do this (C# - just copied from the Internet)
...
da.Fill(dt);
Response.ContentType = "Application/x-msexcel";
Response.AddHeader("content-disposition", "attachment; filename=\"test.csv\"");
Response.Write((new ExportXMLCSV()).ToCSV(dt));
Response.End();
and here the method ToCSV
of the class ExportXMLCSV
(C# - just copied from the Internet)
public string ToCSV(DataTable dataTable)
{
//create the stringbuilder that would hold our data
StringBuilder sb = new StringBuilder();
//check if there are columns in our datatable
if (dataTable.Columns.Count != 0)
{
//loop thru each of the columns so that we could build the headers
//for each field in our datatable
foreach (DataColumn column in dataTable.Columns)
{
//append the column name followed by our separator
sb.Append(column.ColumnName + ',');
}
//append a carriage return
sb.Append("\r\n");
//loop thru each row of our datatable
foreach (DataRow row in dataTable.Rows)
{
//loop thru each column in our datatable
foreach (DataColumn column in dataTable.Columns)
{
//get the value for tht row on the specified column
// and append our separator
sb.Append(row[column].ToString() + ',');
}
//append a carriage return
sb.Append("\r\n");
}
}
//return our values
return sb.ToString();
}
everything just copied from here: http://forums.asp.net/t/1115305.aspx you should be good to go with a little exercise of conversion C# -> VB.NET ;-)