Asp Codes
ActiveX
ADO
Array
Code Snippets
Components
Data Access
Date Time
Files
Graphics
HTML Formatting
Mathematics
Miscellaneous
Sessions
SQL
Strings
Techniques
XML
Asp > SQL sample source codes
Database -- Convert to Comma-Delimited File
Database -- Convert to Comma-Delimited File
dbconvert.asp</TITLE> </head>
<% 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 & "</a>" Else Response.Write "VBScript Errors Occured!
" Response.Write "Error Number=#
" & Err.number & "</b>
" Response.Write "Error Desc. =
" & Err.description & "</b>
" Response.Write "Help Path =
" & err.helppath & "</b>
" Response.Write "Native Error=
" & err.nativeerror & "</b>
" Response.Write "Error Source =
" & Err.source & "</b>
" Response.Write "SQL State=#
" & err.sqlstate & "</b>
" End If %> </body></html>
Privacy Policy
|
Link to Us
|
Links