How to use ASP & Export/Convert to CSV file This is learn/tutorial asp developers how to using aspĀ Read CSV import/insert to Microsoft Access
ShotDev Focus:
- ASP & Read CSV import/insert to Microsoft Access
Example
asp_import_csv.asp
<%Option Explicit%> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <% Dim objFSO,oInStream,sRows,arrRows Dim Conn,strSQL,objExec Dim sFileName sFileName = "shotdev/customer.csv" '*** Create Object ***' Set objFSO = CreateObject("Scripting.FileSystemObject") '*** Check Exist Files ***' If Not objFSO.FileExists(Server.MapPath(sFileName)) Then Response.write("File not found.") Else '*** Open Files ***' Set oInStream = objFSO.OpenTextFile(Server.MapPath(sFileName),1,False) '*** open Connect to Access Database ***' Set Conn = Server.Createobject("ADODB.Connection") Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("shotdev/mydatabase.mdb"),"" , "" Do Until oInStream.AtEndOfStream sRows = oInStream.readLine arrRows = Split(sRows,",") '*** Insert to table customer2 ***' strSQL = "" strSQL = strSQL &"INSERT INTO customer2 " strSQL = strSQL &"(CustomerID,Name,Email,CountryCode,Budget,Used) " strSQL = strSQL &"VALUES " strSQL = strSQL &"('"&arrRows(0)&"','"&arrRows(1)&"','"&arrRows(2)&"' " strSQL = strSQL &",'"&arrRows(3)&"','"&arrRows(4)&"','"&arrRows(5)&"') " Set objExec = Conn.Execute(strSQL) Set objExec = Nothing Loop oInStream.Close() Conn.Close() Set oInStream = Nothing Set Conn = Nothing End If Response.write ("CSV import to access completed.") %> </body> </html>
Create a asp file and save to path root-path/myasp/
Run
http://localhost/myasp/asp_import_csv.asp
Screenshot