將數據成批導入新數據庫的程序例子(Access to Sql)
當前位置:點晴教程→知識管理交流
→『 技術文檔交流 』
前兩天一位朋友在論壇中問到怎樣把數據庫成批倒入另外的數據庫,當時只是簡單的回答了一下用循環(huán)就可以了,正好在我論壇改版碰到原來精華貼子需要倒入到新的數據庫中,于是就寫了下面一段程序來實現(xiàn),很簡單,大家參考一下吧~!
<!--#include file="conn.asp"--> <% dim announceid dim username dim useremail dim boardid dim topic dim body dim dateandtime dim hits dim length dim Expression REM 打開ACCESS數據庫 set uconn=server.createobject("adodb.connection") DBPath = Server.MapPath("club.mdb") uconn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath REM 打開SQL數據庫 set conn=server.createObject("ADODB.Connection") connstr="DSN=aspsky;UID=sa;PWD=" conn.open connstr set urs=uconn.execute("SELECT * FROM bbs1 WHERE isbest=1 ORDER BY announceID") do while not urs.eof announceid=urs("announceid") username=trim(urs("username")) useremail=trim(urs("useremail")) boardid=urs("boardid") topic=trim(urs("topic")) body=trim(urs("body")) dateandtime=urs("dateandtime") hits=urs("hits") length=urs("length") Expression=urs("Expression") dim cmdTemp dim InsertCursor dim dataconn Set DataConn = Server.CreateObject("ADODB.Connection") dataconn.open connstr Set cmdTemp = Server.CreateObject("ADODB.Command") Set InsertCursor = Server.CreateObject("ADODB.Recordset") cmdTemp.CommandText="SELECT * FROM good WHERE (UserName IS NULL)" cmdTemp.CommandType = 1 Set cmdTemp.ActiveConnection = dataconn InsertCursor.Open cmdTemp, , 1, 3 InsertCursor.AddNew InsertCursor("BoardID")=boardID InsertCursor("UserName")=UserName InsertCursor("UserEmail")=UserEmail InsertCursor("Topic")=Topic InsertCursor("Body")=Body InsertCursor("DateAndTime")=DateandTime InsertCursor("hits")=hits InsertCursor("length")=length InsertCursor("Expression")=Expression InsertCursor.Update response.write "轉化紀錄"&announceid&"成功<br>" urs.movenext loop urs.close rs.close set conn=nothing set uconn=nothing %> 該文章在 2012/1/31 9:13:32 編輯過 |
關鍵字查詢
相關文章
正在查詢... |