Use ASP to export the SQL searched content to TXT code

Source: Internet
Author: User

<! -- # 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 a 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 = ""
'-- Write the table column name to txt first
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
'-- Write 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"
%>

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.