[此贴子已经被作者于2007-8-9 10:29:00编辑过]
[此贴子已经被作者于2007-8-9 10:29:00编辑过]
[此贴子已经被作者于2007-8-9 14:12:28编辑过]
'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>"
[此贴子已经被作者于2007-8-9 14:25:49编辑过]
[QUOTE]Do While Not rs.EOF
'列出表内信息
response.write ""&rs(0)&"-"&rs(1)&"-"&rs(2)&"-"&rs(3)&""
cc=cc+1
response.write"<br>"
'添加到数据库只能感
set rssql=server.CreateObject("adodb.recordset")
sql="select * from [user]"
'sql = "insert into [user] (xm,tel,sj,addr) values ('"&rs(0)&"',"&rs(1)&",'"&rs(2)&"','"&rs(3)&"')"
rssql.Open sql,conn,3,3
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
rssql.close
set rssql=nothing
Rs.MoveNext
Loop
end if
response.Write "<script language=javascript>alert('资料导入成功!\n共有"& cc &"条数据导入');history.go(-1)</script>"[/QUOTE]
[此贴子已经被作者于2007-8-9 15:52:32编辑过]
你想把execl里的数据导入到数据库中呀!
你去网上先搜一下,我现在有点忙,晚上有空再试试,我没做过这样的例子。
[url]http://www.845821.com/sc/wyjd/200705/sc_183468.html[/url]
参考一下上面这个