Generate Exel file in Console Application

Posted by Patil_Rakesh under C# on 6/19/2013 | Points: 10 | Views : 752 | Status : [Member] | Replies : 1
Hi ,
I wanted to generate on excel file with large data in Console Application,
Anybody have an idea how to do this,

thanks in advance




Responses

Posted by: Kmandapalli on: 6/19/2013 [Member] Silver | Points: 25

Up
0
Down
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

Login to post response