Avatar of zimmer9
Flag for United States of America asked on

How to export the result set of a SQL Server stored procedure to an Excel spreadsheet using VS2005 for a windows application?

I am writing a C# windows application using VS2005. Do you know how I could rewrite the following routine to export the result of calling a SQL Server stored procedure to an Excel spreadsheet (Excel 2003).

private void FallQueryACSToExcel(string reportyr)
            SqlConnection _conn = new System.Data.SqlClient.SqlConnection("Data Source=;");
            System.Data.SqlClient.SqlCommand comm = _conn.CreateCommand();
            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.CommandText = string.Format("procFlACSExclAAA");
            comm.Parameters.Add("@RptYear", SqlDbType.VarChar, 50).Value = reportyr;
            comm.CommandTimeout = 750;
            System.Data.DataSet dataSet1 = new System.Data.DataSet();
            System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter(comm);
.NET ProgrammingC#

Avatar of undefined
Last Comment
Anuradha Goli

8/22/2022 - Mon

Hi zimmer9,

Take a look here:

exporting sql statement to excel in c#

But I'm executing a Stored Procedure. This is an example when executing a hard coded
SQL Statement.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck