該程式是針對非常龐大的資料庫開發的,沒有用迴圈
用途:
對過萬條資料的資料庫欄位內容批量替換
代碼:
<%
'//資料庫連接
Dim BeeYee_DbName,Connstr,Conn,intSn1
Dim Content,Num,intSn,intIdNo,strCodea,strCodec,Rs,strSql
Server.ScriptTimeOut = 800
BeeYee_DbName="transfer" '修改此處為你的SQL Server 資料庫名稱
YourServer = "seven" '修改此處為你的Sql Server資料庫地址
YourUid = "sa" '修改此處為你的資料庫使用者名稱
YourPassword = "123" '修改此處為你的資料庫密碼
Connstr = "Driver={SQL Server};Server="&YourServer&";Uid="&YourUid&";Pwd="&YourPassword&";Database="&BeeYee_DbName
Set Conn=Server.CreateObject("ADODB.CONNECTION")
On Error Resume Next
Conn.Open Connstr
If Err<>0 Then
err.Clear
Set Conn = Nothing
Response.Write "<div align=center><br><br><br>串連SqlServer資料庫出錯,請檢查相關設定……</div>"
Response.End
End If
'//資料處理部分
intSn = Request("Sn")
intIdNo = Request("IdNo")
If intSn = "" Or Not isNumeric(intSn) Then
intSn = 0
intSn1 = 0
Else
intSn = CLng(intSn)
intSn1 = intSn
End If
If intIdNo = "" Or Not isNumeric(intIdNo) Then
intIdNo = 0
Else
intIdNo = CLng(intIdNo)
End If
strCodea="/newe" '//需要查詢是否包含的字串
strCodeb="/news" '//替換字串
strSql = "Select Top 1 Id,Content,Uptime From News where id>"&intIdNo&" And siteid=1 order by id"
Set Rs = Server.CreateObject("adodb.recordset")
Rs.Open strSql,conn,1,3
If not(rs.eof oR rs.bof) then
Content = Rs("content")
Num = instr(content,strCodea)
If Num>0 then
Content=Replace(content,strCodea,strCodeb)
Rs("Content") = Content
Rs("Uptime") = now()
Rs.Update
intSn = intSn + 1
End If
intIdNo = Rs("Id")
Rs.Close
Set Rs = Nothing
Response.Write("<br><br><br><Div align=center>正在轉換第<font color=red>"&intSn&"</font>條新聞....</Div>")
If intSn = intSn1 Then Response.Write("<br><br><br><Div align=center>新聞中沒有要轉換的東西,程式繼續轉換下一篇</Div>")
Response.write("<meta http-equiv=""refresh"" content=""0;url=?Sn="&intSn&"&IdNo="&intIdNo&""">")
Else
Response.write("<br><br><br><Div align=center>轉換完畢!!共轉換<font color=red>"&intSn&"</font>條新聞.</Div>")
Rs.Close
Set Rs = Nothing
Response.End()
End If
%>