直播中
指定Rs.CursorLocation = adUseClient or 3,下面是一個(gè)完整
的例子:
demo-1.asp (在線(xiàn)演示:http://www.aspcn.com/demo/demo-1.asp)
------------------------------------------------------------
<%@ Language=VBScript %>
<%
'# -------------------------------------------------------------------
---------
'# 程序描述:演示使用斷開(kāi)的記錄集
'# 程序設(shè)計(jì):亞豪
'# -------------------------------------------------------------------
---------
On Error Resume Next
Dim adoConn,adoRs,SQLCmd,ConnectString
'#--------------------------------------------------------------------
---------
'# 使用SQL Server的 DSN-less 方式連接數(shù)據(jù)庫(kù)
'#--------------------------------------------------------------------
---------
ConnectString = "Driver={SQL Server};" & _
"Server=(local);" & _
"Database=abc;" & _
"Uid=sa;" & _
"Pwd=123"
'#--------------------------------------------------------------------
---------
'# 創(chuàng)建對(duì)象實(shí)例,并初始化連接(Connection)
'#--------------------------------------------------------------------
---------
Set adoConn = Server.CreateObject("ADODB.Connection")
Set adoRs = Server.CreateObject("ADODB.Recordset")
adoConn.Open ConnectString
SQLCmd = "Select * from bbs_user where LTrim(RTrim(id)) = 'w3org'"
'#--------------------------------------------------------------------
---------
'# 使用客戶(hù)端臨時(shí)表打開(kāi)并保存記錄集,關(guān)鍵所在!
'# 客戶(hù)端是運(yùn)行ASP程序的主機(jī),相對(duì)于數(shù)據(jù)庫(kù)服務(wù)器而言
'#--------------------------------------------------------------------
---------
adoRs.CursorLocation = 3 'Const adUseClient = 3
adoRs.Open SQLCmd,adoConn,0,2
'#--------------------------------------------------------------------
---------
'# 沒(méi)有發(fā)現(xiàn)記錄,結(jié)束程序
'#--------------------------------------------------------------------
---------
Err.Clear
If adoRs.EOF And adoRs.BOF Then
adoRs.Close
adoConn.Close
Set adoRs = Nothing
Set adoConn = Nothing
Response.Write "用戶(hù)沒(méi)有發(fā)現(xiàn)!"
Response.End
End If
'#--------------------------------------------------------------------
---------
'# 找到記錄,顯示原來(lái)的值后釋放記錄集的活動(dòng)連接,之后關(guān)閉數(shù)據(jù)庫(kù)連接
'#--------------------------------------------------------------------
---------
Response.Write "原來(lái)的昵稱(chēng)是:" & Trim(adoRs.Fields("NickName").Value)
& "<br>" & vbCrLf
Set adoRs.ActiveConnection = Nothing '釋放Rs的活動(dòng)連接
adoConn.Close
Response.Write "連接已經(jīng)關(guān)閉!<br>" & vbCrLf
'#--------------------------------------------------------------------
---------
'# 賦一個(gè)新的值給記錄的 NickName 列,這時(shí)已經(jīng)沒(méi)有活動(dòng)的數(shù)據(jù)庫(kù)連接
'#--------------------------------------------------------------------
---------
adoRs.Fields("NickName").Value = "NewTest-" & Second(Time())
'#--------------------------------------------------------------------
---------
'# 再次打開(kāi)數(shù)據(jù)庫(kù)連接,并綁定到先前的記錄集上
'#--------------------------------------------------------------------
---------
adoConn.Open ConnectString
adoRs.ActiveConnection = adoConn
'#--------------------------------------------------------------------
---------
'# 更新記錄集,并顯示新的值
'#--------------------------------------------------------------------
---------
adoRs.Update
Response.Write "新的昵稱(chēng)是:" & Trim(adoRs.Fields("NickName").Value) &
"<br>" & vbCrLf '顯示一個(gè)結(jié)果
'#--------------------------------------------------------------------
---------
'# 如果發(fā)生錯(cuò)誤則顯示錯(cuò)誤
'#--------------------------------------------------------------------
---------
If Err.number <> 0 Then
Response.Write "發(fā)生錯(cuò)誤:" & Err.description & "<br>"
End If
adoRs.Close
adoConn.Close
Set adoRs = Nothing
Set adoConn = Nothing
%>
<HTML>
<HEAD><Title>演示斷開(kāi)的連接</title></HEAD>