Export SQL to proper CSV file

  • 15 years ago

    Hi,


    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!


    Thanks,


    Al

  • 15 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).

Contribute

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.

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” - Donald Knuth