<% whichname="/upload/tests/authors.txt" myDSN="DSN=Student;uid=student;pwd=magic" mySQL="select * from authors where au_id<100" showblank="" shownull="" linestart=Chr(34) lineend=Chr(34) delimiter=Chr(34) & "," & Chr(34) delimitersub="" whichFN=Server.MapPath(whichname) Set fstemp = Server.CreateObject("Scripting.FileSystemObject") Set filetemp = fstemp.CreateTextFile(whichFN, True) ' true = file can be over-written if it exists ' false = file CANNOT be over-written if it exists Set conntemp=Server.CreateObject("adodb.connection") conntemp.open myDSN Set rstemp=conntemp.execute(mySQL) ' this code detects if data is empty If rstemp.eof Then Response.Write "No data to convert for SQL statement
" Response.Write mySQL & "
" connection.close Set connection=Nothing Response.End End If Do UNTIL rstemp.eof thisline=linestart For Each whatever In rstemp.fields thisfield=whatever.value If IsNull(thisfield) Then thisfield=shownull End If If Trim(thisfield)="" Then thisfield=showblank End If thisfield=Replace(thisfield,delimiter,delimitersub) thisline=thisline & thisfield & delimiter Next tempLen=Len(thisline) tempLenDelim=Len(delimiter) thisline=Mid(thisline,1,tempLEN-tempLenDelim) & lineend filetemp.WriteLine(thisline) ' response.write thisline & "
" rstemp.movenext Loop filetemp.Close Set filetemp=Nothing Set fstemp=Nothing rstemp.close Set rstemp=Nothing conntemp.close Set conntemp=Nothing If Err.number=0 Then Response.Write "File was converted sucessfully!
" Response.Write "Converted file is at " & whichname & "" Else Response.Write "VBScript Errors Occured!
" Response.Write "Error Number=#" & Err.number & "
" Response.Write "Error Desc. =" & Err.description & "
" Response.Write "Help Path =" & err.helppath & "
" Response.Write "Native Error=" & err.nativeerror & "
" Response.Write "Error Source =" & Err.source & "
" Response.Write "SQL State=#" & err.sqlstate & "
" End If %>