Export SQL to proper CSV file

  • 13 years ago


    I am having real problems creating an application that exports data from an SQL database to a proper CSV file. If there is no value present in the column then I am after a comma to be inserted before moving onto the next field.

    If anyone has or can write me a bit of code to loop through a table a create a true .csv file in C# that would be fantastic!



  • 13 years ago

    You can use ADO.NET to read and write CSV files just like they were tables in a database.  Check out www.connectionstrings.com for the appropriate connection string.  The only other difference is that you use the file names in place of table names in your SQL statements.  I'm not sure whether it will create the files from scratch.  If not, you would just have to manually create the file with a header row and let ADO.NET take care of the rest.

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Nine people can't make a baby in a month.” - Fred Brooks