用ASP實作從SQL Server匯出資料到Access或Excel文件
作者:Eve Cole
更新時間:2009-06-25 17:44:33
前段時間,我在網路上發出這樣的問題,現在已經解決,現將程式碼共享,
希望對IntranetMIS愛好者有幫助
方法其實很簡單:需要在SQL Server連線中嵌套一個access連接,然後逐條寫入就可以了。
<%set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "driver={SQL server};server=mamaco;uid=linner;pwd=123;dat
abase=linner"
sql="select * from scjh"
set rs=conn.execute (sql)%>
<%set Conn1 = Server.CreateObject("ADODB.Connection")
param = "driver={Microsoft Access Driver (*.mdb)}"
conn.Open param & ";dbq=" & Server.MapPath("scjh.mdb")
conn1.execute("delete from scjh")%>
<%do while not rs.eof%>
<%dim ktdh,scph,scts,jhqtsj,yhxdsj,yxj,rwbh
ktdh=rs("ktdh")
scph=rs("scph")
scts=rs("scts")
jhqtsj=rs("jhqtsj")
yhxdsj=rs("yhxdsj")
yxj=rs("yxj")
rwbh=rs("rwbh")
%>
<%sql1="insert into scjh(ktdh,scph,scts,jhqtsj,yhxdsj,yxj,rwbh)
values
('"& ktdh &"','" & scph & "'," & scts
& ",'"&jhqtsj&"','"&yhxdsj&"',"&
yxj &"," & rwbh &")"
conn1.execute (sql1)%>
<%rs.movenext
loop
conn1.close
conn.close%>
<%response.redirect "/download/scjh.mdb"%>