2 chenshigang416 chenshigang416 于 2013.03.15 08:55 提问

asp中excel数据导入到access数据库

//上传excel文件页面
//一个页面获取到excel文件 然后提交到导入数据的asp页面进行处理,但现在提交到导入功能的页面以后报服务器错误,不知道错误出在了哪里

c
excel导入公益性岗位信息
excel文件:

//数据导入页面 xining为表名 通过excel中录入数据来导入到表xining中


<%
session.CodePage=936
Server.ScriptTimeOut=6000000
set upload = new upload_5xsoft
set file = upload.file("file1")
if file.fileSize>12000000 then
%> alert("文件过大"); window.close();

<%
end if
if file.fileSize>0 then
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&secone(now)
filename=file.filename+".";
filenameend=file.filename
filenameend=split(filenameend,".")
if filenameend(1)="xls" then
filename = filename&filenameend(1)
file.saveAs Server.mappath("uploadfile/"filename)
else
response.write"数据格式不对/不是excel文件"
response.write"返回"
response.end()
end if
set file=nothing
else
response.write"文件格式不能为空"
response.write"返回"
response.end()
end if
set file=nothing

'读入到数据库'
setAddr = Server.mappath("uploadfile/"filename)
set excelconn = server.createobject("adodb.connection")
excelconn.open"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = "+strAddr+";Extended"

Properties = "Excel 8.0;HDR=NO;IMEX=1"
set rs = server.CreateObject("adodb.recordset")
set rs1 = server.CreateObject("adodb.recordset")
sql = "select * from [Sheet1$]"
rs.open.sql,excelconn,1,1
if not(rs.bof and rs.eof)then
rs.movenext
do while not rs.eof
sql1 = "select * from xining where id is null"
rs1.open sql1,excelconn,1,3
rs1.addnew
rs1("name")=rs(0)
rs1("sex")=rs(1)
rs1("nation")=rs(2)
rs1("education")=rs(3)
rs1("idcard")=rs(4)
rs1("empcard")=rs(5)
rs1("worktype")=rs(6)
rs1("workname")=rs(7)
rs1("company")=rs(8)
rs1("memo")=rs(9)
rs1.update
rs1.close
rs.movenext
loop
end if
rs.close()
set rs=nothing

%>

alert("导入成功"); window.parent.document.location.reload(); history.back();
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!