Comma separated file:
using (SqlConnection con = new SqlConnection(sqlConnectionString))
{
con.Open();
SqlCommand cmd = new SqlCommand("select query from report_query where query_id=@id", con);
cmd.Parameters.AddWithValue("@id", id);
string query = cmd.ExecuteScalar().ToString();
cmd.CommandText = query;
cmd.CommandTimeout = 0;
SqlDataReader rReader = cmd.ExecuteReader();
string reportName = string.Format("ReportEX_{0}.csv" , id);
while(rReader.Read())
{
StringBuilder oneRow = new StringBuilder();
for(int ii = 0; ii < rReader.FieldCount; ii++)
{
oneRow.AppendFormat("{0},", rReader[ii]);
}
oneRow.Append(Environment.NewLine);
File.AppendAllText(reportName, oneRow.ToString());
}
}