unnamed
unnamed

Reputation: 856

How to export Sql Server Data to Excel File in C#

How can one read sql server data and write it to excel file in C#? Do I need to use an external .Net library, or is it just OK using Visual Studio itself?

Any example and link will be well appreciated..

Note: Please send examples for Winforms, not asp.net

Upvotes: 0

Views: 15535

Answers (5)

Thorsten Hans
Thorsten Hans

Reputation: 2683

I would use some kind of OR-Mapper to read data from SQL such as

  • NHibernate
  • Entity Framework
  • Linq 2 SQL

For writing data to Excel you could bind hardly to any Excel Version by referencing the Excel Assemblies. The cleaner and more beautiful way is to use Open XML SDK for Office http://www.microsoft.com/download/en/details.aspx?id=5124

Upvotes: 2

Adam
Adam

Reputation: 1264

See : http://www.dotnetfunda.com/forums/thread548-export-data-to-excel-file-from-a-table-in-sql-server-using-csharp.aspx

It also has a nice example on the link inside the page.

Upvotes: 1

Damyan Bogoev
Damyan Bogoev

Reputation: 696

You could find helpful information how to achieve that goal in the following blog posts: 1. http://msmvps.com/blogs/deborahk/archive/2009/07/23/writing-data-from-a-datatable-to-excel.aspx 2. http://tim.mackey.ie/HowtoExportADatasetToExcelCAspnet.aspx

Upvotes: 1

MUS
MUS

Reputation: 1450

Follow the below article, this even provide the facility to export the data into many formats.

Export data to Excel and other formats using C#

Upvotes: 1

Related Questions