Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > ASP > ASP Excel (Excel.Application) > ASP Upload Excel Import to Database (Excel.Application)


ASP Upload Excel Import to Database (Excel.Application)

ASP Import Excel to Database (Excel.Application) ตัวอย่างนี้จะเป็นการเขียน ASP กับ Excel อ่านข้อมูลจาก Excel แล้วนำเข้าฐานข้อมูล Microsoft Access

Config Excel.Application


Asp aspSmartUpload



AspUploadExcelImportToDatabase.html

01.<html>
02.<head>
03.<title>ThaiCreate.Com ASP Excel.Application Tutorial</title>
04.</head>
05.<body>
06.<form action="AspUploadExcelImportToDatabase.asp" method="post" enctype="multipart/form-data" name="frmMain">
07.Upload
08.<input name="file1" type="file">
09.<input type="submit" name="Submit" value="Submit">
10.</form>
11.</body>
12.</html>



AspUploadExcelImportToDatabase.asp

01.<% Option Explicit %>
02.<html>
03.<head>
04.<title>ThaiCreate.Com ASP Excel.Application Tutorial</title>
05.</head>
06.<body>
07.<%
08.    Dim xlApp,xlBook,xlSheet1,xlSheet2,OpenFile,i
09.    Dim Conn,strSQL,objExec
10.    Dim mySmartUpload
11.    Dim sFileName
12. 
13.    '*** Upload By aspSmartUpload ***'
14. 
15.    '*** Create Object ***'
16.    Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
17. 
18.    '*** Upload Files ***'
19.    mySmartUpload.Upload
20. 
21.    '** Getfile Name ***'
22.    sFileName = mySmartUpload.Files("file1").FileName
23. 
24.    If sFileName <> "" Then
25.         
26.        mySmartUpload.Files("file1").SaveAs(Server.MapPath("MyXls/"&sFileName))
27. 
28.        OpenFile = "MyXls/"&sFileName
29. 
30.        '*** Create Exce.Application ***'
31.        Set xlApp = Server.CreateObject("Excel.Application")
32.        Set xlBook = xlApp.Workbooks.Open(Server.MapPath(OpenFile))
33.        Set xlSheet1 = xlBook.Worksheets(1)    
34. 
35.        Set Conn = Server.Createobject("ADODB.Connection")
36.        Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("MyXls/mydatabase.mdb"),"" , ""
37. 
38.        For  i = 2 To 5
39.            If Trim(xlSheet1.Cells.Item(i,1)) <> "" Then         
40.                strSQL = ""
41.                strSQL = strSQL &"INSERT INTO customer2 "
42.                strSQL = strSQL &"(CustomerID,Name,Email,CountryCode,Budget,Used) "
43.                strSQL = strSQL &"VALUES "
44.                strSQL = strSQL &"('"&xlSheet1.Cells.Item(i,1)&"','"&xlSheet1.Cells.Item(i,2)&"', '"&xlSheet1.Cells.Item(i,3)&"' "
45.                strSQL = strSQL &",'"&xlSheet1.Cells.Item(i,4)&"','"&xlSheet1.Cells.Item(i,5)&"', '"&xlSheet1.Cells.Item(i,6)&"') "
46.                Set objExec = Conn.Execute(strSQL)
47.                Set objExec = Nothing
48.            End IF
49.        Next
50. 
51.        xlApp.Application.Quit
52. 
53.        '*** Quit and Clear Object ***'
54.        Conn.Close()
55.        Set Conn = Nothing
56.        Set xlSheet1 = Nothing
57.        Set xlBook = Nothing
58.        Set xlApp = Nothing
59.    End If
60.     
61.    Set mySmartUpload = Nothing
62.%>
63.Data Import/Inserted <a href="mydatabase.mdb">Click here</a> to Download.
64.</body>
65.</html>

Screenshot

ASP & Excel


ASP & Excel

ASP & Excel

   
Hate it
Don't like it
It's ok
Like it
Love it
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-09-27 21:23:04 / 2009-05-10 23:19:50
  Download : Download  ASP Upload Excel Import to Database (Excel.Application)
 Sponsored Links / Related

 
ASP Excel Response.ContentType = "application/vnd.ms-excel"
Rating :

 
ASP Config Excel (Excel.Application)
Rating :

 
ASP Connect to Excel.Application
Rating :

 
ASP Write Excel (Excel.Application)
Rating :

 
ASP Delete Sheet Excel (Excel.Application)
Rating :

 
ASP Write Excel Multiple Sheet (Excel.Application)
Rating :

 
ASP Write Excel Style & Format (Excel.Application)
Rating :

 
ASP Excel Merge Cell (Excel Application)
Rating :

 
ASP Read Excel (Excel.Application)
Rating :

 
ASP Excel Cell Border (Excel Application)
Rating :

 
ASP Read Excel Multiple Sheet (Excel.Application)
Rating :

 
ASP Excel Draw Line (Excel Application)
Rating :

 
ASP ADO Excel (DRIVER={Microsoft Excel Driver (*.xls)})
Rating :

 
ASP Excel Insert Picture (Excel Application)
Rating :

 
ASP ADO Excel List Record Paging/Pagination (Microsoft Excel Driver (*.xls))
Rating :

 
ASP Excel Open Document (Excel Application)
Rating :

 
ASP Import Excel to Database (Excel.Application)
Rating :

 
ASP Export Database to Excel (Excel.Application)
Rating :

 
ASP Export Database to Excel Report/Print Format (Excel.Application)
Rating :

 
ASP Convert to Excel and Send Email Attachment
Rating :


ThaiCreate.Com Forum
Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่