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

  • Home
  • SEARCH
  • 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 8902411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:36:23+00:00 2026-06-15T01:36:23+00:00

Part of my current project involves populating an Excel worksheet from a large SQL

  • 0

Part of my current project involves populating an Excel worksheet from a large SQL table, which contains 120,000+ records. I’m currently using SqlDataReader with a while loop to directly populate a new Excel sheet, but obviously this takes an unrealistic amount of time. Building a local .CSV file with StringBuilder then opening that in Excel seems to be a faster option. Is it preferred to dump the data to file every thousand rows or so, or write it all at once? Or is there a more efficient way to import this data that I’m not considering?

The dataset is different depending on user input, so I can’t simply append to an existing file.

Current code:

SqlConnection cnnct = new SqlConnection("Data Source=Source;Initial Catalog=Catalog;Integrated Security=True;");
            cnnct.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cnnct;
            string cmdText = "SELECT * FROM TABLE";
            cmd.CommandText = cmdText;

            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                columnChar = 'A';
                rowCount++;

                cellName = columnChar.ToString() + rowCount.ToString();
                    ws.get_Range(cellName, cellName).Value2 = dr["EXAMPLE_FIELD"].ToString();
                    columnChar++;
                //The above three lines are identical for each field (there are 26)
            }
  • 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-06-15T01:36:25+00:00Added an answer on June 15, 2026 at 1:36 am

    Well, I would avoid Excel interop at all costs. Your idea of just writing a .CSV file has lots of merit. As always with “best” performance it depends on environment, but unit tests always help.

    System.IO is pretty optimal. I would just read a row from SqlDataReader and write the CSV line. It becomes very simple code and I bet is fairly “fast”.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As part of my current project I am required to download images from a
As part of my current project I've been tasked with collecting URL's for various
As part of my current project I've created a custom class loader. Part of
I am working on a project which basically involves parsing and storing information about
I've finished my current part-time project and am looking for something new. I've decided
On a current project I'm using a helper class to make API calls, which
As a part of my current pet project, I have to write an program
In the current project I need to communicate with third-party web services from .NET.
I am using com.sun.net.httpserver.HttpsServer in my current project which deals with client-authentification etc.. Currently
My current project is getting awfully large. I have dozens of activities, adapters, fragments,

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.