Export to csv (or excel)

Hi - OK - this is my first dive into .NET - and I’m finding it taxing :frowning:

I have a MSSQL table which I want to export to csv (or excel format).

It already have my database connection sorted and I have selected the table and table fields… but now what?

I have read lots of options - like making a DataGrid and exporting from there, bcp export (I’m still not sure if that is only from command line or using .NET).

I’m just looking for a simple export table… csv will be fine (espeically if excel is more difficult)

Can anymore point me to a good article or in the right direction please.


There are a few options to this, and you definitely don’t need to think about getting outside managed code:

a) If CSV is really what you are after, you could use FileHelpers to help you create it.
b) If your client/boss is ok with XML spreadsheets (which work with Excel 2002+), you can use the CarlosAG excel xml writer (see [this blog post)
c) If you want to make office 2007+ compatible excel (.xslx) files, you can do so natively in managed code using ExcelPackage