欢迎光临
我们一直在努力

在ASP中使用断开的记录集-ASP教程,ASP应用

建站超值云服务器,限时71元/月

在asp中使用断开的记录集

  我们在使用asp 内置的ado组件进行数据库编程时,通常是在脚本的开头打开一个连接,并在脚本的最后关闭它,但是就较大脚本而言,在多数情况下连接打开的时间要比它需要打开的时间长得多。因此为了节省服务器资源,应该尽可能关闭连接以释放连接所占有的资源,这种关闭记录集的连接而不关闭记录集的技术叫做断开记录集,这个记录集本身则称为断开的记录集。

  下面我们就通过一个实例来说明这种技术的使用方法(northwind.mdb是microsoft access97自带的一个数据库,文件adovbs.inc可在c:\program files\common files\system\ado下找到):

<% @language = vbscript %>

<%

response.expires = 0

dim cnn,objrs, strout, strq, strc

strc= "driver={microsoft access driver (*.mdb)}; dbq=" & server.mappath("\asp24")

& "\northwind.mdb;"

建立连接

set cnn = server.createobject("adodb.connection")

cnn.open strc

创建recordset对象

set objrs = server.createobject("adodb.recordset")

objrs.cursorlocation =aduseclient

objrs.cursortype = adopenstatic

objrs.locktype = adlockoptimistic

strq = "select 运货商id, 公司名称, 电话 from 运货商 "

objrs.open strq, cnn, , , adcmdtext

set objrs.activeconnection = nothing   断开记录集

cnn.close                 关闭连接

set cnn = nothing

response.write ""

下面使用断开的记录集

do while (not objrs.eof)

strout = objrs("运货商id") & ", " & objrs("公司名称") & ", " & objrs("电话")

response.write server.htmlencode(strout) & "

"

objrs.movenext

loop

response.write "

准备新增或插入记录: "

若需要更新数据库, 则要重新建立连接

set cnn = server.createobject("adodb.connection")

cnn.open strc

set objrs.activeconnection = cnn

objrs.filter = "公司名称 = 吴丰"

if objrs.eof then

objrs.addnew

objrs("公司名称") = "吴丰"

objrs("电话") = "571-7227298"

objrs.update

response.write "符合该条件的记录不存在, 则新增.

"

else

objrs("电话") = "571-7227071"

response.write "符合该条件的记录存在, 则 update.

"

objrs.update

end if

set objrs.activeconnection = nothing

cnn.close

set cnn = nothing

objrs.close

set objrs = nothing

response.write ""

%>

  由于篇幅所限,笔者点到为止,有兴趣可去我的主页 http://wuf.bentium.net 下载更多的源程序,另外也可参考vb6.0的msdn文档中有关ado的部分。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 在ASP中使用断开的记录集-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章