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.
-
dim tablename
-
tablename = request.querystring("tablename")
-
pathtodatabase = "D:/webspace/broomtacklebox.co.uk/db/broomtacklebox.mdb"
-
'This is the location to Write the CSV File - physical path.
-
filesavepath = "D:/webspace/broomtacklebox.co.uk/wwwroot/csv/" & tablename & ".csv"
-
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source="
-
ConnStr = ConnStr & pathtodatabase
-
set open = Server.CreateObject("ADODB.Connection")
-
open.open ConnStr
-
SQL = "SELECT * FROM " & tablename
-
Set RS = open.execute(SQL)
-
dim filesavepath
-
Dim F, Head
-
-
set FSO = Server.CreateObject("scripting.FileSystemObject")
-
set csvfile = fso.CreateTextFile(filesavepath, true)
-
For Each F In RS.Fields
-
Head = Head & "," & replace(F.Name,"_"," ")
-
Next
-
Head = Mid(Head,3) & vbCrLf
-
Body = RS.GetString(,,",",vbCrLf,"")
-
csvfile.WriteLine(Head)
-
csvfile.WriteLine(Body)
-
csvfile.Close
-
'virtual path. This will enable the user to click on the link and download the csv file.
-
Response.Write "edirectory csv files: <a href=""http://www.broomtacklebox.co.uk/csv/" & tablename & ".csv"">Download CSV File by clicking here</a>"
-
regards
Tog