📄 upfile.asp
字号:
<%OPTION EXPLICIT%>
<%Server.ScriptTimeOut=5000%>
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<title>文件上传</title>
</head>
<body>
<%
dim upload,file,formName,formPath,iCount,fname
set upload=new upload_5xsoft ''建立上传对象
dim fid,city1,city2,city3,nian,yue
fid=upload.form("xiao")
if(upload.form("xiao")<>"") then
fid=upload.form("xiao")
else if(upload.form("zhong")<>"") then
fid=upload.form("zhong")
else if(upload.form("da")<>"") then
fid=upload.form("da")
else
fid=upload.form("sz")
end if
end if
end if
city1=upload.form("city1")
city2=upload.form("city2")
city3=upload.form("city3")
nian=upload.form("nian")
yue=upload.form("yue")
for each formName in upload.objFile ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath("data/"&file.FileName) ''保存文件
fname=file.FileName
iCount=iCount+1
end if
set file=nothing
next
set upload=nothing ''删除此对象
%>
<%
Dim PatnNow
PatnNow="data/"&fname
'=====================ASP读取EXCEL注事项===========================
'i)将Excel97或Excel2000生成的XLS文件(book)看成一个数据库,其中的每一个工作表(sheet)看成数据库表
'ii)ADO假设Excel中的第一行为字段名.所以你定义的范围中必须要包括第一行的内容
'iii)Excel中的行标题(即字段名)不能够包含数字. Excel的驱动在遇到这种问题时就会出错的。例如你的行标题名为“F1”
'iiii)如果你的Excel电子表格中某一列同时包含了文本和数字的话,那么Excel的ODBC驱动将不能够正常, 处理这一行的数据类型,
'你必须要保证该列的数据类型一致
'===========================================================
Dim ConnXls,Driver,DBPath,Rs,conn1
' 建立Connection对象
Set conn1 = Server.CreateObject("ADODB.Connection")
conn1.Open"Provider=sqloledb;user id=sa;password=yghjbn;initial catalog=infoprice;data source=."
Set ConnXls = Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Excel Driver (*.xls)};"
DBPath = "DBQ=" & Server.MapPath(PatnNow)
'调用Open 方法打开数据库
ConnXls.Open Driver & DBPath
'DSN连接方式
'ConnXls.Open "Dsn=test"
'注意 表名一定要以下边这种格试 "[表名$]" 书写
Sql="Select * From [Sheet1$] "
Set Rs=ConnXls.Execute(Sql)
IF Rs.Eof And Rs.Bof Then
Response.write "<br><br>没有找到您需要的数据!!"
Else
Do While Not Rs.EOF
dim sql
sql="insert into cl(cl_bh,cl_title,cl_xh,cl_dw,cl_zhj,cl_ajg,cl_bjg,cl_cjg,cl_djg,cl_ejg,cl_fjg,cl_cd,cl_dj,cl_pp,cl_yj,cl_bz1,cl_bz2,cl_bz3,classid,provinceid,cityid,areaid,addtime) values ('"&Rs("代码")&"','"&Rs("材料名称")&"','"&Rs("型号规格")&"','"&Rs("单位")&"','"&Rs("信息价")&"','"&Rs("供应价")&"','"&Rs("到工地价")&"','"&Rs("C价格")&"','"&Rs("D价格")&"','"&Rs("E价格")&"','"&Rs("F价格")&"','"&Rs("产地")&"','"&Rs("等级")&"','"&Rs("品牌")&"','"&Rs("厂商")&"','"&Rs("地区")&"','"&Rs("供货单位及电话")&"','"&Rs("备注3")&"','"&fid&"','"&city1&"','"&city2&"','"&city3&"','"&nian&"-"&yue&"-1')"
conn1.execute(sql)
'Response.write Rs("接入号")&"<br>"
Rs.MoveNext
Loop
End IF
Rs.Close
Set Rs=nothing
ConnXls.Close
Set ConnXls=Nothing
'Response.Write "成功!"
conn1.close
set conn1=nothing
response.write "<script>alert('导入成功!');</script>"
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -