SqlConnection connection = new SqlConnection(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=PSeminar;Integrated Security=true;Trusted_Connection=Yes;MultipleActiveResultSets=true");
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() + ",";
data += SQLRD[2].ToString() + ",";
data += SQLRD[3].ToString() + ",";
data += SQLRD[4].ToString() + ",";
data += SQLRD[5].ToString() + ",";
data += SQLRD[6].ToString() + ",";
data += SQLRD[7].ToString();
data += "\n";
}
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();
Currently my code does not display a dialog box for the user to specify the file location. It is “hardcoded” to always store in @”C:\download.csv”;. In replace of this i want to use a dialog box.
First of all I’d say do not use
System.Stringobject tocontactstrings. Always use System.Text.StringBuilder object.To download data,