Exporting into csv

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

H

I used the following statement to dump the results of a SQL- query into excel file, which works quite fine. But now, I need the output to be in csv- format, but I can't find a key word for that. Can anyone help me

' g is a valid OleDbComman
g.CommandText = "SELECT * INTO [Excel 8.0;DATABASE=C:\mytest.xls;HDR=NO;].Table1 FROM [MainTable] WHERE ..
g.ExecuteNonQuery(

So, how do I dump just the same output, but in csv format, to file

Thanks for any help
 
Hi Anreas,

I did make this to export a CSV file from a dataset for Scorpion thursday,
maybe you can give it a try (if you are using VB.net). (The only thing you
need to change is the name of your table at the places ds.tables("scorpion")
and the path of the csv file you want.

And look at that comma, it think that tab is better (That was what Cindy
from the Excel group told once) .

I hope this helps?

Cor

\\\
Dim Scorpion As New ArrayList
For i As Integer = 0 To ds.Tables("scorpion").Rows.Count - 1
Dim row As New System.Text.StringBuilder
Scorpion.Add(row)
row.append("""")
For y As Integer = 0 To ds.Tables("scorpion").Columns.Count - 1
row.Append(ds.Tables("scorpion").Rows(i)(y).tostring)
If y <> ds.Tables("scorpion").Columns.Count - 1 Then
row.Append(""",""")
' or if you want it with a tab
' row.Append("""")
' row.Append(chr(09))
'' row.Append("""")
else
row.Append("""")
End If
Next
Next
Dim sw As New IO.StreamWriter("C:\Scorpion.csv")
For i As Integer = 0 To Scorpion.Count - 1
sw.WriteLine(Scorpion(i).ToString)
Next
sw.Flush()
sw.Close()
///
 
Hi somaris,

We have reviewed your post. We will do some research on your issue. We will
reply to you ASAP.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
¤ Hi
¤
¤ I used the following statement to dump the results of a SQL- query into excel file, which works quite fine. But now, I need the output to be in csv- format, but I can't find a key word for that. Can anyone help me?
¤
¤ ' g is a valid OleDbCommand
¤ g.CommandText = "SELECT * INTO [Excel 8.0;DATABASE=C:\mytest.xls;HDR=NO;].Table1 FROM [MainTable] WHERE ...
¤ g.ExecuteNonQuery()
¤
¤ So, how do I dump just the same output, but in csv format, to file?
¤
¤ Thanks for any help

g.CommandText = "SELECT * INTO [Text;DATABASE=D:\My Documents\TextFiles;HDR=NO;].[Table1.csv] FROM
[MainTable] WHERE ...


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Hi,

Thank you for posting in the community! My name is Kevin, and I will be
assisting you on this issue.

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to export the results a SQL
query to an .csv file instead of an Excel file. If there is any
misunderstanding, please feel free to let me know.

Just as Paul mentioned, we can use the Text File Driver to output the
result set. We can use the following as the command text.

g.CommandText = "SELECT * INTO [Text;DATABASE=D:\My
Documents\TextFiles;HDR=NO;].[Table1.csv] FROM
[MainTable] WHERE ...

As this feature is supported by ISAM, we can use it in a Access database,
but not in a SQL server.

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top