Using ASP to export the contents of SQL search to txt code _javascript tips

Source: Internet
Author: User
Tags chr
<!--#include file= "inc/conn.asp"-->
<%
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
'--Create TXT file
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 "No Data"
Else
Dim strline,responsestr
Strline= ""
'--Writes the table's column name first to TXT
For each x in Rs.fields
StrLine = strLine & X.name & Chr (9)
Next
MyFile.WriteLine StrLine
Do but not Rs. Eof
Strline= ""
For each x in Rs. Fields
StrLine = strLine & X.value & Chr (9)
Next
'--writes table data to TXT
MyFile.WriteLine StrLine
Rs. MoveNext
Loop
End If
Rs. Close
Set rs = Nothing
Response.contenttype= "Application/x-msdownload"
Response.Redirect "Download.txt"
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.