0

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

2

5 Answers 5

2

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

1

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#

1

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

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.