一页是form 表,是选择excel的,现在提交页面代码如下;
'sql 连接驱动
dim conn,connstr,time1,time2,db
db="data/wx.mdb"
time1=timer
Server.ScriptTimeOut = 100
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
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"
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")
' sql="select * from user"
sql = sql = "insert into [user] (xm,tel,sj,addr) values ('"&rs(0)&"','"&rs(1)&"','"&rs(2)&"','"&rs(3)&"')"
rssql.Open sql,conn,2,2
rssql.AddNew
if rs(0)<>"" then
rssql(1)=rs(0)
end if
if rs(1)<>"" then
rssql(2)=rs(1)
end if
if rs(2)<>"" then
rssql(3)=rs(2)
end if
if rs(4)<>"" then
rssql(4)=rs(3)
end if
rssql.Update
Rs.MoveNext
Loop
rssql.close
set rssql=nothing
end if
response.Write "<script language=javascript>alert('资料导入成功!\n共有"&cc&"条数据导入');history.go(-1)</script>"