Try this code, it will help you to export data from database into excel.
static void Main(string args)
SqlConnection myConnection = null;
SqlDataReader rdr = null;
myConnection = new SqlConnection(connection string); //The connectionstring will be assigned here.
SqlCommand cmd = new SqlCommand(storedprocName, myConnection);//Stored procedure name is assigned //here
cmd.CommandType = CommandType.StoredProcedure;
rdr = cmd.ExecuteReader();
program.CreateXLSFile(rdr, fileName); //Here the program is the class name that calls the CreateXLSFile().
if (myConnection != null)
Mark as Answer if satisfied.
Patil_Rakesh, if this helps please login to Mark As Answer. | Alert Moderator