467,076 Members | 977 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,076 developers. It's quick & easy.

creating a csv file and losing a letter

Hello all.
here is a little conundrum for you to get your teeth into.

I am creating a csv file from an access database. The code I use is below and it works well .. except for one small annoying feature. When it creates the csv file the first letter of the name of the first field is missing. The database field name is Start of Record - and in the csv file it becomes Tart of Record.
I can overcome this by renaming the database field SStart of Record, but this is a poor way of fixing it and I would like to know why it is happening.

Expand|Select|Wrap|Line Numbers
  1. dim tablename
  2. tablename = request.querystring("tablename")
  3. pathtodatabase = "D:/webspace/broomtacklebox.co.uk/db/broomtacklebox.mdb"
  4. 'This is the location to Write the CSV File - physical path.
  5. filesavepath = "D:/webspace/broomtacklebox.co.uk/wwwroot/csv/" & tablename & ".csv"
  6. ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source="
  7. ConnStr = ConnStr & pathtodatabase
  8. set open = Server.CreateObject("ADODB.Connection")
  9. open.open ConnStr
  10. SQL = "SELECT * FROM " & tablename
  11. Set RS = open.execute(SQL)
  12. dim filesavepath
  13. Dim F, Head
  15. set FSO = Server.CreateObject("scripting.FileSystemObject")
  16. set csvfile = fso.CreateTextFile(filesavepath, true)
  17. For Each F In RS.Fields
  18.     Head = Head & "," & replace(F.Name,"_"," ")
  19. Next
  20. Head = Mid(Head,3) & vbCrLf
  21. Body = RS.GetString(,,",",vbCrLf,"")
  22. csvfile.WriteLine(Head)
  23. csvfile.WriteLine(Body)
  24. csvfile.Close
  25. 'virtual path. This will enable the user to click on the link and download the csv file.
  26. Response.Write "edirectory csv files: <a href=""http://www.broomtacklebox.co.uk/csv/" & tablename & ".csv"">Download CSV File by clicking here</a>"

Feb 14 '07 #1
  • viewed: 1278

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Your Name | last post: by
7 posts views Thread by Micheal Artindale | last post: by
reply views Thread by Andrew Westgarth | last post: by
2 posts views Thread by deja@chronofish.com | last post: by
2 posts views Thread by RickH | last post: by
7 posts views Thread by Burden | last post: by
2 posts views Thread by Rene | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.