您好,欢迎访问一九零五行业门户网

用ASP将SQL搜索出来的内容导出为TXT的代码_javascript技巧

dim rs,sql,filename,fso,myfile,x
set fso = server.createobject(scripting.filesystemobject) 
filename = server.mappath(download.txt) 
if fso.fileexists(filename) then 
fso.deletefile(filename) 
end if 
'--创建txt文件 
set myfile = fso.createtextfile(filename,true)
set rs = server.createobject(adodb.recordset) 
sql = select * from userfile 
rs.open sql,conn,1,1 
if rs.eof and rs.bof then 
response.write 无数据 
else 
dim strline,responsestr 
strline= 
'--将表的列名先写入txt 
for each x in rs.fields 
strline = strline & x.name & chr(9) 
next 
myfile.writeline strline 
do while not rs.eof 
strline= 
for each x in rs.fields 
strline = strline & x.value & chr(9) 
next 
'--将表的数据写入txt 
myfile.writeline strline 
rs.movenext 
loop 
end if 
rs.close 
set rs = nothing 
response.contenttype=application/x-msdownload 
response.redirect download.txt 
%>
其它类似信息

推荐信息