<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP Excel.Application Tutorial</title>
</head>
<body>
<%
Dim xlApp,xlBook,xlSheet1,xlSheet2,OpenFile,i
Dim Conn,strSQL,objExec
Dim mySmartUpload
Dim sFileName
'*** Upload By aspSmartUpload ***'
'*** Create Object ***'
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
'*** Upload Files ***'
mySmartUpload.Upload
'** Getfile Name ***'
sFileName = mySmartUpload.Files("file1").FileName
If sFileName <> "" Then
mySmartUpload.Files("file1").SaveAs(Server.MapPath("MyXls/"&sFileName))
OpenFile = "MyXls/"&sFileName
'*** Create Exce.Application ***'
Set xlApp = Server.CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(Server.MapPath(OpenFile))
Set xlSheet1 = xlBook.Worksheets(1)
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("MyXls/mydatabase.mdb"),"" , ""
For i = 2 To 5
If Trim(xlSheet1.Cells.Item(i,1)) <> "" Then
strSQL = ""
strSQL = strSQL &"INSERT INTO customer2 "
strSQL = strSQL &"(CustomerID,Name,Email,CountryCode,Budget,Used) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('"&xlSheet1.Cells.Item(i,1)&"','"&xlSheet1.Cells.Item(i,2)&"', '"&xlSheet1.Cells.Item(i,3)&"' "
strSQL = strSQL &",'"&xlSheet1.Cells.Item(i,4)&"','"&xlSheet1.Cells.Item(i,5)&"', '"&xlSheet1.Cells.Item(i,6)&"') "
Set objExec = Conn.Execute(strSQL)
Set objExec = Nothing
End IF
Next
xlApp.Application.Quit
'*** Quit and Clear Object ***'
Conn.Close()
Set Conn = Nothing
Set xlSheet1 = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End If
Set mySmartUpload = Nothing
%>
Data Import/Inserted <a href="mydatabase.mdb">Click here</a> to Download.
</body>
</html>