Access的数据导入到Mysql

<%
dim driverName,chs
driverName="Driver={mysql odbc 3.51 driver};server=localhost;database=discuz;uid=root;pwd=;"
set conn=server.createobject("adodb.connection")
conn.open driverName

Set conns=Server.CreateObject("ADODB.Connection")
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath("news.mdb")&""
On Error Resume Next
Conns.open ConnStr
If Err Then
Err.Clear
Set Conns = Nothing
Response.Write "连接数据库错误……"
Response.End
End If

'之前先执行下面这一句,这句是解决读取数据库乱码问题的关键
set chs=conn.Execute("SET NAMES 'gb2312'")

IntId = Request.QueryString("IntId")
If Len(IntId)<1 Or IsNumeric(IntId)=False Then
IntId=0
Else
IntId=CLng(IntId)
End If

Set Rs = Server.CreateObject("Adodb.Recordset")

'取得当前处理的数据
Set Rs = Server.CreateObject("Adodb.Recordset")
Rs.Open "Select top 1 * From info Where id>"&IntId&" Order by id asc",conns,1,1
If Not Rs.Eof Then
aid=Rs("id")
Title=Trim(Rs("Title"))
Content=Trim(Rs("Content"))
Content=Replace(Content,"&nbsp;"," ")
Content=Replace(Content,"?","")
Content = Replace(Content, "<br>", CHR(10))
Content = Replace(Content, CHR(13), CHR(10))
Content = Replace(Content, CHR(10)&CHR(10), CHR(10))
Else
Response.Write "处理完毕!"
Response.End()
End If
Rs.Close

'取得最大pid
Rs.Open "Select * FROM cdb_posts order by pid desc limit 1",Conn,1,1
NewPid=Rs("pid")+1
Rs.Close

'取得最大dateline
Rs.Open "Select * FROM cdb_threads order by dateline desc limit 1",Conn,1,1
NewDateline=Rs("dateline")+1
Rs.Close

'insert


'取得最大tid
Rs.Open "Select * FROM cdb_threads order by tid desc limit 1",Conn,1,1
NewTid=Rs("tid")+1
Rs.Close

'写入cdb_threads表
Rs.Open "Select * FROM cdb_threads where 1=2",Conn,1,3
Rs.Addnew
   Rs("tid")=NewTid
   Rs("fid")=10
   Rs("iconid")=0
   Rs("typeid")=0
   Rs("readperm")=0
   Rs("price")=0
   Rs("authorid")=1
   Rs("dateline")=NewDateline
   Rs("lastpost")=NewDateline
   Rs("views")=0
   Rs("replies")=0
   Rs("displayorder")=0
   Rs("highlight")=0
   Rs("digest")=0
   Rs("rate")=0
   Rs("blog")=0
   Rs("special")=0
   Rs("attachment")=0
   Rs("subscribed")=0
   Rs("moderated")=0
   Rs("closed")=0
   Rs("itemid")=0
   Rs("supe_pushstatus")=0
Rs.update
Rs.Close

Sql2="update cdb_threads set author='admin',subject='"&Title&"',lastposter='admin' where tid="&NewTid
Conn.execute(sql2)

'----------------------------------


'写入cdb_posts
Rs.Open "Select * FROM cdb_posts where 1=2",Conn,1,3
Rs.Addnew
   Rs("pid")=NewPid
   Rs("fid")=10
   Rs("tid")=NewTid
   Rs("first")=1
   Rs("authorid")=1
   Rs("dateline")=NewDateline
   Rs("invisible")=0
   Rs("anonymous")=0
   Rs("usesig")=0
   Rs("htmlon")=0
   Rs("bbcodeoff")=-1
   Rs("smileyoff")=-1
   Rs("parseurloff")=0
   Rs("attachment")=0
   Rs("rate")=0
   Rs("ratetimes")=0
   Rs("status")=0
Rs.update
Rs.Close
Set Rs = Nothing

Sql2="update cdb_posts set author='admin',subject='"&Title&"',message='"&Content&"',useip='127.0.0.1' where pid="&NewPid
Conn.execute(sql2)

Response.Write "<br><br><br><br><div align=center>已经成功转移了<b>"&IntId&"</b>条数据,数据编号是<b>"&aid&"</b>!</div>"
Response.Write "<script>location.href(""?IntId="&IntId+1&""");</script>"

%>

你可能感兴趣的:(Access)