web 2.0

How to use ASP & Export/Convert database to CSV

How to use ASP & Export/Convert database to CSV This is learn/tutorial asp developers how to using aspĀ  Export/Convert database to CSV

ShotDev Focus:
- ASP & Export/Convert database to CSV

Example

asp_database_csv.asp


<%Option Explicit%>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
Dim objFSO,oFiles
Dim Conn,strSQL,objRec
Dim sFileName

'*** Connect to Access ***'
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("shotdev/mydatabase.mdb"),"" , ""
strSQL = "SELECT * FROM customer "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3

If Not objRec.EOF Then

sFileName = "shotdev/customer.csv"

'*** Create Object ***'
Set objFSO = CreateObject("Scripting.FileSystemObject")

'*** Create Text Files ***'
Set oFiles = objFSO.CreateTextFile(Server.MapPath(sFileName), 2)

While Not objRec.EOF
oFiles.WriteLine(objRec.Fields("CustomerID").Value&","&_
objRec.Fields("Name").Value&","&_
objRec.Fields("Email").Value&","&objRec.Fields("CountryCode").Value&","&_
objRec.Fields("Budget").Value&","&objRec.Fields("Used").Value)
objRec.MoveNext()
Wend

oFiles.Close()
Set oFiles = Nothing
Set objFSO = Nothing

Response.write"Generate CSV completed.<br><a href="&sFileName&">Download</a>"

End If

objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
</body>
</html>

Create a asp file and save to path root-path/myasp/

Run
http://localhost/myasp/asp_database_csv.asp

Screenshot

ASP & Export/Convert database to CSV

ASP & Export/Convert database to CSV

.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.