Hi,
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;
try
{
myConnection = new SqlConnection(connection string); //The connectionstring will be assigned here.
myConnection.Open();
SqlCommand cmd = new SqlCommand(storedprocName, myConnection);//Stored procedure name is assigned //here
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(Parameters);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
program.CreateXLSFile(rdr, fileName); //Here the program is the class name that calls the CreateXLSFile().
}
}
catch (Exception)
{
throw;
}
finally
{
if (myConnection != null)
myConnection.Close();
}
}
Mark as Answer if satisfied.
Regards,
Shree M.
Kavya Shree Mandapalli
Patil_Rakesh, if this helps please login to Mark As Answer. | Alert Moderator