<%Option Explicit%>
<html>
<head>
<title>ThaiCreate.Com ASP & Import CSV To Access</title>
</head>
<body>
<%
Dim objFSO,oInStream,sRows,arrRows
Dim Conn,strSQL,objExec
Dim sFileName
sFileName = "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("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 Done.")
%>
</table>
</body>
</html>