Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:30:11+00:00 2026-05-25T20:30:11+00:00

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;

  • 0
 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:30:11+00:00Added an answer on May 25, 2026 at 8:30 pm

    First of all I’d say do not use System.String object to contact strings. Always use System.Text.StringBuilder object.

    System.Text.StringBuilder sb = new System.Text.StringBuilder();
     while (SQLRD.Read())
      {
      sb.Append(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}\n",
          SQLRD[0],SQLRD[1],SQLRD[2],SQLRD[3],SQLRD[4],SQLRD[5],SQLRD[6],SQLRD[7]));
       }
    

    To download data,

    byte[] ar = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
    Response.ClearContent();
    Response.ClearHeaders();
    Response.AddHeader("Content-Type", "application/octet-stream");
    Response.AddHeader("Content-Length", ar.Length.ToString());
    Response.AddHeader("Content-Disposition", "attachment; filename=download.csv");
    Response.BinaryWrite(ar);
    Response.Flush();
    Response.End();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if (validateEmailId(email)) { pictureBox5.Visible = true; SqlConnection con = new SqlConnection(conection string); SqlCommand cmd2
I had someting like this in my code (.Net 2.0, MS SQL) SqlConnection connection
Does Java Connection.close rollback into a finally block?. I know .Net SqlConnection.close does it.
I'm diong a typical Windows Integrated Connection from a .Net Winforms Application: Dim sqlConnetion
In C++, how can I establish an SQL connection to store data in an
It's easy to bind a data source to something like a gridview or repeater,
I have a function like this try { using(var sConnection = new SqlConnection(ConnectionString)) using(var
I like the Add Connection or SQL Connection dialog that is in Visual Studio
My code for sql connection using linq is: var query1 = from u in
My question is concerning SQL connection status, load, etc. based on the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.