01.
<%
Option
Explicit%>
02.
<html>
03.
<head>
04.
<title>ThaiCreate.Com ASP & Import CSV
To
Access</title>
05.
</head>
06.
<body>
07.
<%
08.
Dim
objFSO,oInStream,sRows,arrRows
09.
Dim
Conn,strSQL,objExec
10.
Dim
sFileName
11.
12.
sFileName =
"customer.csv"
13.
14.
15.
Set
objFSO = CreateObject(
"Scripting.FileSystemObject"
)
16.
17.
18.
If
Not
objFSO.FileExists(Server.MapPath(sFileName))
Then
19.
Response.write(
"File not found."
)
20.
Else
21.
22.
23.
Set
oInStream = objFSO.OpenTextFile(Server.MapPath(sFileName),1,
False
)
24.
25.
26.
Set
Conn = Server.Createobject(
"ADODB.Connection"
)
27.
Conn.Open
"DRIVER=Microsoft Access Driver (*.mdb);DBQ="
& Server.MapPath(
"mydatabase.mdb"
),
""
,
""
28.
29.
30.
Do
Until
oInStream.AtEndOfStream
31.
sRows = oInStream.readLine
32.
arrRows = Split(sRows,
","
)
33.
34.
strSQL =
""
35.
strSQL = strSQL &
"INSERT INTO customer2 "
36.
strSQL = strSQL &
"(CustomerID,Name,Email,CountryCode,Budget,Used) "
37.
strSQL = strSQL &
"VALUES "
38.
strSQL = strSQL &
"('"
&arrRows(0)&
"','"
&arrRows(1)&
"','"
&arrRows(2)&
"' "
39.
strSQL = strSQL &
",'"
&arrRows(3)&
"','"
&arrRows(4)&
"','"
&arrRows(5)&
"') "
40.
Set
objExec = Conn.Execute(strSQL)
41.
Set
objExec =
Nothing
42.
Loop
43.
44.
oInStream.Close()
45.
Conn.Close()
46.
Set
oInStream =
Nothing
47.
Set
Conn =
Nothing
48.
49.
End
If
50.
51.
Response.write (
"CSV Import to Access Done."
)
52.
%>
53.
</table>
54.
</body>
55.
</html>