asp上传excle文件并导入到access数据库

<%
function FSOFileDel(filename)
Dim objFSO,objCountFile,FiletempData
On Error Resume Next
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objCountFile =objFSO.DeleteFile(Server.MapPath(filename),true)
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End Function




dim action,files
action=trim(request("action"))
files=trim(request("files"))
select case action
case "add"
call add(files)
case else
call default()
end select        
%>

<%sub default()%>
<form action="?action=add" method="post" id="form1" name="form1">
<table border="0" cellspacing="0" cellpadding="0">
<tr class="title2">
<td colspan="2">批量上传</td>
</tr>
<tr>
<td>1.上传Excle文件&nbsp;</td>
<td><input name="files" type="hidden" id="files" />
<iframe frameborder="0" scrolling="no" height="25" width="400" src="upload.asp?action=add"></iframe>&nbsp;</td>
</tr>
<tr>
<td>2.点击"开始上传"&nbsp;</td>
<td>  <label>
<input type="submit" name="button" id="button" value="开始上传" />
</label>&nbsp;</td>
</tr>
</table>



</form>
<%end sub%>
<%
sub add(files)
dim FileName

if files="" then ClientAlert"请先上传Excle文件","?"

FileName="../upload/file/"&files  '取得文件路径
Dim connEX
set connEX=CreateObject("ADODB.connection")
connEX.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
"DriverId=790;" & _
"Dbq=" & server.mappath(""&FileName&"") & ";" & _
"DefaultDir=G:/"

set rs=createobject("ADODB.recordset")
rs.Open "Select * From [Sheet1$]",connEX, 2, 2
if rs.eof then
response.write "Excel表中无纪录"
else
'  set connDB = Server.CreateObject("ADODB.Connection")
'  DBPath = Server.MapPath("excel.mdb")
'  'RESPONSE.WRITE DBpath
'  connDB.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
Set RsDB = Server.CreateObject("ADODB.Recordset")
SqlDB="Select * from product"
RsDB.open sqlDB,conn,1,3
do while not  rs.eof '利用循环读出数据
RsDB.addnew
RsDB("ProName")=rs(0)
RsDB("ProClassId")=rs(1)
RsDB("ProPics")=rs(2)
RsDB("ProPic")=rs(3)
RsDB("ProFeaturesCn")=rs(4)
RsDB("IsNew")=rs(5)
RsDB("IsHot")=rs(6)
RsDB("Taxis")=rs(7)
Rs.update
RsDB.movenext
rs.movenext
loop
'response.redirect FileName
end if
RsDB.movefirst
if RsDB.eof then
response.write "数据库中无记录"
end if
rs.close
set rs=nothing
set connEX=nothing

Call FSOFileDel("../upload/file/"&files)'导入成功后及时删除上传文件.

ClientAlert"导入成功,点确定继续。","?"
end sub

%>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值