Please visit our sponsor
UNKNOWN
'**************************************
' Name: Write to File
' Description:Writes to a file, jsut cha
' nge a few things and there you go!
' By: Woody Woodland
'
'
' Inputs:None
'
' Returns:None
'
'Assumes:None
'
'Side Effects:None
'This code is copyrighted and has limite
' d warranties.
'Please see http://www.Planet-Source-Cod
' e.com/xq/ASP/txtCodeId.6099/lngWId.4/qx/
' vb/scripts/ShowCode.htm
'for details.
'**************************************
sub saveit
'create a new Active Data Objects connection
set conn = server.createobject("ADODB.RecordSet")
'open the ODBC System DSN
conn.open "usage",dsn, adOpenKeySet, adLockPessimistic, adCmdTable
conn.addnew
conn("email")=Request.Form("email")
conn("IP")=Request.ServerVariables("REMOTE_ADDR")
conn("referer")=request.form("referer")
conn("browser")=Request.ServerVariables("HTTP_USER_AGENT")
conn("date_time")=now
conn.update
conn.close
set conn = Nothing
end sub
sub query2csv(dsn,sql)
whichname="download/contacts.txt"
myDSN=dsn
mySQL=sql
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
end sub