Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag 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=;");
            _conn.Open();
            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);
            sqlDataAdapter1.Fill(dataSet1);
Avatar of Rimvis
Rimvis
Flag of Lithuania image

Hi zimmer9,

Take a look here:

exporting sql statement to excel in c#
http://sql2005ted.blogspot.co.uk/2012/02/exporting-sql-statement-to-excel-in-c.html
Avatar of zimmer9

ASKER

But I'm executing a Stored Procedure. This is an example when executing a hard coded
SQL Statement.
SOLUTION
Avatar of Rimvis
Rimvis
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial