protected void btnDownload_Click(object sender, EventArgs e)
{
SqlCommand Command = connection.CreateCommand();
SqlDataReader SQLRD;
Command.CommandText = "Select *from Attendance";
connection.Open();
SQLRD = Command.ExecuteReader();
string data = "";
while (SQLRD.Read())
{
data += SQLRD[0].ToString();
data += SQLRD[1].ToString();
}
SQLRD.Close();
connection.Close();
string filename = @"C:\download.csv";
FileStream fs = new FileStream(filename,FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(data);
sw.Flush();
sw.Close();
fs.Close(); }
This is what I have so far. I want to store all the data from the above query in a file. This file will be downloaded.
EDITED CODE: just copy paste in your code and change filename path