当前位置: 首页 > 网络学院 > 服务端脚本教程 > ADO > ADO提升执行速度
Use the GetString() method to speed up your ASP script (instead of using multiple Response.Write's).
我们可以使用GetString()来提升ASP脚本的运行速度(以此替代对“Response.Write”指令的多次使用)。
Using GetString()
使用GetString()
How to use GetString() to display data from a recordset in an HTML table.
如何使用GetString()来显示一个HTML表单中一条记录所包含的数据信息。
The following example demonstrates one way of how to display a database query in an HTML table:
下面这个例子演示了在HTML表单中显示数据库查询信息的方法:
<html> <% set rs = Server.CreateObject("ADODB.recordset") <table border="1" width="100%"> <% </body> |
For a large query, this can slow down the script processing time, since many Response.Write commands must be processed by the server.
如果查询的信息量比较大,上述代码会增加脚本的运行时间,因为Response.Write命令是在服务器端执行的。
The solution is to have the entire string created, from <table> to </table>, and then output it - using Response.Write just once.
上述问题的解决办法就是将争端字符串写入<table>和</table>之间,然后输出它,这样的话你只要使用一次“Response.Write”指令。
The GetString() method allows you to display the string with only one Response.Write. It also eliminates the do...loop code and the conditional test that checks if the recordset is at EOF.
GetString()方法允许你只使用一次“Response.Write”指令来显示字符串。它将不再使用“do...loop”代码,不再对是否位于记录的EOF[末尾]进行条件测试。
str = rs.GetString(format,rows,coldel,rowdel,nullexpr) |
To create an HTML table with data from a recordset, we only need to use three of the parameters above (all parameters are optional):
我们只需用到上述的所有参数中的三个(上述所有参数都是可选择使用的)就可以创建一个带有记录数据的HTML表:
Note: The GetString() method is an ADO 2.0 feature. You can download ADO 2.0 at http://www.microsoft.com/data/download.htm.
注意:GetString()仅在ADO 2.0中获得支持。你可以通过下列网址下载ADO2.0:http://www.microsoft.com/data/download.htm。
In the following example we will use the GetString() method to hold the recordset as a string:
在下面的案例当中,我们将使用GetString()以字符串的的形式获取记录值:
<html> <% set rs = Server.CreateObject("ADODB.recordset") str=rs.GetString(,,"</td><td>","</td></tr><tr><td>"," ") <table border="1" width="100%"> <% </body> |
The str variable above contains a string of all the columns and rows returned by the SQL SELECT statement. Between each column the HTML </td><td> will appear, and between each row, the HTML </td></tr><tr><td> will appear. This will produce the exact HTML we need with only one Response.Write.
上述的“Str”变量包含了通过SQL SELECT语句返回的列字符串和行字符串。每个纵列之间将包含“</td><td>”的HTML代码;在每个横行之间将包含“</td></tr><tr><td>”的HTML代码。这样一来,我们只需要使用一次“Response.Write”指令就可以创作出精确的HTML代码了。