感谢版主,我试了但还是不行,以下是整个asp文件的代码,希望能再指点一下,谢谢···
<%
dim upfile,formPath,ServerPath,FSPath,formName,FileName,oFile,upfilecount
upfilecount=0
set upfile=new clsUp ''建立上传对象
upfile.NoAllowExt="asp;exe;htm;html;aspx;cs;vb;js;"
'设置上传类型的黑名单
upfile.GetData (1024000)
'取得上传数据,限制最大上传10M
if upfile.isErr then
'如果出错
select case upfile.isErr
case 1
Response.Write "没有上传数据"
case 2
Response.Write "上传的文件超出限制,最大1M"
end select
else
FSPath=GetFilePath(Server.mappath("updata.asp"),"\")'取得当前文件在服务器路径
FSPath=FSPath&"upload\" '上传到upload文件夹
ServerPath=GetFilePath(Request.ServerVariables("HTTP_REFERER"),"/")'取得在网站上的位置
for each formName in upfile.file '列出所有上传了的文件
set oFile=upfile.file(formname)
FileName=upfile.form(formName)'取得文本域的值
if not FileName>"" then
FileName=oFile.filename'如果没有输入新的文件名,就用原来的文件名
upfile.SaveToFile formname,FSPath&FileName '保存文件 也可以使用AutoSave来保存,参数一样,但是会自动建立新的文件名
if upfile.iserr then
Response.Write upfile.errmessage
else
upfilecount=upfilecount+1
Response.Write "上传成功"
end if
'将数据读入数据库
dim conn
dim conn2
'连接目的数据表
set conn=CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Data Source=" & Server.MapPath("sddb.mdb")
'连接待读入excel数据表
set conn2=CreateObject("ADODB.Connection")
conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=;Extended properties='Excel 5.0;hdr=yes;imex=1';Data Source="& Server.MapPath("upload/"&FileName)
'查询待读入excel数据表
sql = "SELECT * FROM [Sheet1$]"
set rs = conn2.execute(sql)
'将数据循环读入目的数据库
while not rs.eof
'查询相同的数据,以学号为唯一标识
dim icount
checksamesql="select roomno from cost_sd where roomno = '"& fixsql(rs(0)) &"'"
set checksamers = conn.execute(checksamesql)
icount = checksamers.recordcount
'checksamers.close
set checksamers= nothing
if icount<=0 then
sql = "insert into cost_sd(roomno,user_sd,water,eletricity,moon_sd,year_sd) values('"& fixsql(rs(0)) &"','"& trim(fixsql(rs(1))) &"','"& fixsql(rs(2)) &"','"& fixsql(rs(3)) &"','"& fixsql(rs(4)) &"','"& fixsql(rs(5)) &"')"
conn.execute(sql)'
提示在这一行出错
end if
rs.movenext
wend
set oFile=nothing'释放文件对象
next
set upfile=nothing'释放上传对象
'释放数据连接对象
conn.close
set conn = nothing
conn2.close
set conn2 = nothing
'删除上传数据表
Set fso = CreateObject("Scripting.FileSystemObject")
FiLePaTh = Server.MapPath("upload/"&FileName)
If
fso.FileExists(FiLePaTh) Then
fso.DeleteFile(FiLePaTh)
end if
Set fso = nothing
response.Write "<script LANGUAGE='javascript'>alert('数据导入成功!');history.go(-1);</script>"
response.End
end if
'取得文件上传路径
function GetFilePath(FullPath,str)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, str))
Else
GetFilePath = ""
End If
End function
'检查读入数据,有效性验证,可以修改你要过滤的符号
function fixsql(str)
dim newstr
newstr = str
if isnull(newstr) then
newstr = ""
else
newstr =Replace(newstr ,"'","‘")
newstr =Replace(newstr ,"%","%")
newstr =Replace(newstr ,"-","-")
newstr =Replace(newstr ,">","〉")
newstr =Replace(newstr ,"<","〈")
newstr =Replace(newstr ,"&","&")
newstr =Replace(newstr,";",";")
newstr =Replace(newstr ,"+","+")
newstr =Replace(newstr ,"[","[")
newstr =Replace(newstr ,"]","]")
newstr =Replace(newstr ,"{","{")
newstr =Replace(newstr ,"}","}")
newstr =Replace(newstr ,"(","(")
newstr =Replace(newstr ,")",")")
newstr =Replace(newstr ,"""","''")
end if
fixsql = newstr
end function
%>