getstring方法_用getstring提高ASP运行速度

更新时间:2013-12-19    来源:php与数据库    手机版     字体:

【www.bbyears.com--php与数据库】

许多asp程序员都有过执行数据库查询,然后将查询结果用html表格的形式显示出来的
经历吧.通常我们是这么做的:
<%
"createconnection/recordset
"populatedataintorecordsetobject
%>

<%dowhilenotrs.eof%>

<%=rs("field1")%>
<%=rs("field2")%>
...

<%rs.movenext
loop%>

如果查询结果很多,服务器解释你的aspscript将花费大量的时间,因为有许多的
response.write语句要处理.如果你将输出的全部结果放在一个很长的字符串里(从
到),那么服务器只需解释一遍response.write语句,速度就会快得
多.微软公司里的一些能干的家伙已经将想法变成了现实.(注意,这是一个ado2.0
才有的特性.如果你还在使用ado1.5话,可以在
http://www.microsoft.com/data/download.htm免费下载ado2.0)
有了getstring方法,我们就可以仅用一个response.write来显示所有的输出了,它就
象是能判断recordset是否为eof的do...loop循环.
getstring的用法如下(所有的参数都是可选的):
string=recordset.getstring(stringformat,numrows,columndelimiter,
rowdelimiter,nullexpr)
要从recordset的结果里生成html表格,我们只需关心getstring的5个参数中的3个:
columndelimiter(分隔记录集的列的html代码),rowdelimiter(分隔记录集的行的
html代码),和nullexpr(当前记录为空时应生成的html代码).就象你在下面生成
html表格的例子里所看到的那样,每列用...分隔,每行用...分
隔.来看看例子的代码吧.
<%@language="vbscript"%>
<%optionexplicit"goodcodingtechnique
"establishconnectiontodb
dimconn
setconn=server.createobject("adodb.connection")
conn.open"dsn=northwind;"
"createarecordset
dimrs
setrs=server.createobject("adodb.recordset")
rs.open"select*fromtable1",conn
"storeouronebigstring
dimstrtable
strtable=rs.getstring(,,"",""," ")%

本文来源:http://www.bbyears.com/jiaocheng/2821.html