[asp]代码库
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%'sql 连接驱动
dim conn,connstr,time1,time2,mdb
time1=timer
'如果是sql 2000数据库,请用下面 连接驱动
connstr = "Driver={SQL Server};server=.;uid=sa;pwd=abcHSPMS;database=HSPMS;"
'如果是Access数据库,请用下面 连接驱动
'connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(mdb/jmgl2007.mdb)
Set conn = Server.Createobject("ADODB.Connection")
conn.Open connstr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"
Response.End
End If
sub closedb()
conn.close
set conn=nothing
end sub
dim aa
aa=request.form("bbb") '获取传递过来的值
Dim StrConnect,cc
Dim objConn
Dim rs
Dim Sql
cc=0
'Excel连接驱动
aaa="provider=Microsoft.Jet.OLEDB.4.0; Data Source="&aa&";Extended Properties='Excel 8.0;HDR=yes;IMEX=1'"
set StrConnect=CreateObject("ADODB.Connection")
StrConnect.Open aaa
Set objConn=CreateObject("ADODB.Connection")
objConn.Open StrConnect
'注意表名一定要以下边这种格试 "[表名$]" 书写
Set rs = Server.CreateObject("ADODB.Recordset")
Sql="select * from [sheet1$] "
rs.Open Sql,StrConnect,2,2
IF rs.Eof And Rs.Bof Then
response.Write("<script>alert('没有资料可以导入!');history.go(-1)</script>")
else
Do While Not rs.EOF
'列出表内信息
response.write"excel数据为: <br>"
'response.write ""&rs(0)&"-"&rs(1)&"-"&rs(2)&""
response.write"<br>"
set rssql=server.CreateObject("adodb.recordset")
'插入SQL2000里
rssql.Open "SELECT PT_PARTCODE, 供应商代码,供应商名称, htj FROM 供应商合同价 ",conn,1,3
rssql.AddNew
if rs(0)<>"" then
rssql(0)=rs(0)
end if
if rs(1)<>"" then
rssql(1)=rs(1)
end if
if rs(2)<>"" then
rssql(2)=rs(2)
end if
if rs(3)<>"" then
rssql(3)=rs(3)
end if
rssql.Update
Rs.MoveNext
Loop
end if
response.Write"<script language=javascript>alert('合同价导入成功!\n共有"&cc&"条数据导入');history.go(-1)</script>"
%>
[源代码打包下载]
初级程序员
by: 樱桃可乐 发表于:2021-10-11 17:35:29 顶(0) | 踩(0) 回复
感谢
回复评论