<%
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")
'===========================================
' 函数功能:数据批量导入
' 作 者:wangsdong
' 文章为作者原创,转载请注明文章出处、保留作
' 者信息,谢谢支持!
' 原理:将excel中的数据导入到access
'===========================================
'连接excel数据库教程
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="商品"
file2="商品列表"
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 While not xlsrs.eof
goods_name=xlsrs("商品名")
goods_images=xlsrs("图片")
cat_id=xlsrs("商品分类")
%>
<TR>
<TD> <%=goods_name%></TD>
<TD> <%=goods_images%></TD>
<TD> <%=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 "共导入<font color='red'>" & i-1 & "</font>条记录.<br>" & vbCrLf
set xlsconn=nothing
set objCmd=nothing
%>
access 结构
goods_name,goods_images cat_id
excel结构
商品名,图片,商品分类