asp實現(xiàn)將excel中的數(shù)據(jù)批量導(dǎo)入到access
...
asp數(shù)據(jù)批量導(dǎo)入的原理是使用excel保存許多數(shù)據(jù),然后將這個excel使用無組件上傳到服務(wù)器上,然后打開excel,將里面的數(shù)據(jù)寫入到數(shù)據(jù)庫中。
這里我寫的是將excel中的數(shù)據(jù)讀出來,然后寫入到數(shù)據(jù)庫中
具體代碼:
<!-- #include file="adoconn.asp" -->
< %
連接excel數(shù)據(jù)庫
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 "共導(dǎo)入<font color=red>" & i-1 & "</font>條記錄.<br>" & vbCrLf
set xlsconn=nothing
set objCmd=Nothing
% >
下一條:ASP字符串函數(shù)大全