Bulk import data from Excel into Access

Source: Internet
Author: User

<%

db= "Db1.mdb"
Path=server.mappath (DB)
Set Conn=server.createobject ("ADODB. Connection ")
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" &path
Conn. Open ConnStr
Set Rs=server. CreateObject ("Adodb.recordset")

'===========================================
' function function: Data Bulk Import
' Author: wangsdong
' Article for the author original, reproduced please indicate the origin of the article, reserved for
' Person information, thank you for your support!
' Principle: Import data from Excel into Access
'===========================================

' Connecting to the Excel database tutorial
Path= "./"
Dim Xlsconn,strsource,xlbook,xlsheet,i
Dim Myconn_xsl,xlsrs,sql,objcmd
Set xlsconn = server. CreateObject ("Adodb.connection")
Set Xlsrs = Server.CreateObject ("Adodb.recordset")

Filename= "Merchandise"
file2= "Product List"
Source=server.mappath (path&filename& ". xls")

Myconn_xsl= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" "&source&"; Extended Properties=excel 8.0 "
Xlsconn.open myconn_xsl

sql = "SELECT * FROM [" &file2& "$]"
Xlsrs.open sql,xlsconn,1,1
If xlsrs.eof Then
Else
I=1
Response.Write "<table border=1>"
Do as not xlsrs.eof
Goods_name=xlsrs ("Commodity name")
Goods_images=xlsrs ("Picture")
CAT_ID=XLSRS ("Commodity Classification")
%>

<TR>
<TD>&nbsp;<%=goods_name%></TD>
<TD>&nbsp;<%=goods_images%></TD>
<TD>&nbsp;<%=cat_id%></TD>
</TR>

<%
Sql= INSERT into goods (goods_name,goods_images,cat_id) VALUES (' &goods_name& ', ' &goods_images& ' , "&cat_id&") "
Conn.execute (SQL)
I=i+1
Xlsrs. MoveNext
Loop
Response.Write "</table>"
End If
Xlsrs.close

Response.Write "Total import <font color= ' Red ' >" & i-1 & "</font> Strip record .<br>" & VbCrLf

Set xlsconn=nothing
Set objcmd=nothing
%>

Access structure
Goods_name,goods_images cat_id

Excel structure
Product name, picture, product category

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.