How to export from Access to CSV?

  • Thread starter Thread starter Brett
  • Start date Start date
B

Brett

I'd like to see pseudo code (or actual example is better) explaining how to
export data from an MS Access table to a CSV file.

Thanks,
Brett
 
read the data into a dataset or datareader and write the data out to a file

something like this (written from scratch)

dim writerCSV as new Streamwriter("c:\output.csv")
for i as integer = 0 to dataset.tables(0).rows.count-1
writerCSV.writeline("whatyou" & "," & "want" & "," & "to write")
next
writerCSV.close

be careful with errors on null values

hth Peter
 
("whatyou" & "," & "want" & "," & "to write") are column inside of the
table? Why isn't there any dot notation on them that points to the
datareader? Such as

datareaderVar.Item("column1")

or was that just for the psuedo code?

Thanks,
Brett
 
Hi Herfried

I didn't know of the acExportDelim, so I just keep learning every day

thnx,

greetz Peter

PS the second link you sent didn't work
 
¤ I'd like to see pseudo code (or actual example is better) explaining how to
¤ export data from an MS Access table to a CSV file.

The following will export with the column names in the first row of the CSV file:

Function ExportAccessToText() As Boolean

Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=e:\My Documents\db1.mdb")

AccessConn.Open()

Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO [Text;DATABASE=e:\My
Documents\TextFiles].[Table3.csv] FROM Table_3", AccessConn)

AccessCommand.ExecuteNonQuery()
AccessConn.Close()

End Function


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

just the say the second link does work, but 2 minutes a go it didn't, I
think it's time for me to go home ;-)

greetz Peter
 
Hi Brett,

that was just pseudo code, but look at the link Herfried sent or the code
Paul sent I think those are easier solutions then writing it out yourself.

Greetz Peter
 
Back
Top