Using GetString to increase the speed of ASP
Many ASP programmers have the experience of executing a database query and then displaying the results of the query in an HTML form. That's what we usually do:
<%
' Create Connection/recordset
' Populate data into Recordset object
% >
< TABLE >
<% do While not Rs. EOF% >
< TR >
< TD ><%=rs ("Field1")% ></td >
< TD ><%=rs ("Field2")% ></td >
...
</tr >
<% Rs. MoveNext
Loop% >
</table >
If the query results are many, the server will spend a lot of time explaining your ASP script because there are a lot of Response.Write statements to be processed. If you put all the results of the output in a long string (from < TABLE > to </table >), the server simply interprets the Response.Write statement once more quickly. Some of the most capable guys in Microsoft have turned their ideas into reality. (Note that this is a feature of ADO 2.0. If you're still using ADO 1.5, you can download ADO 2.0 at http://www.microsoft.com/data/download.htm free)
With the GetString method, we can display all the output with just one Response.Write, which is like a do ... that can tell if the recordset is EOF. Loop loop.
The use of GetString is as follows (all parameters are optional):
String = Recordset. GetString (StringFormat, NumRows, ColumnDelimiter, RowDelimiter, nullexpr)
To generate an HTML table from the result of the recordset, we only care about 3 of the 5 parameters of GetString: ColumnDelimiter (the HTML code that separates the recordset's columns), RowDelimiter (the HTML code that separates the rows of the Recordset), and nullexpr (HTML code that should be generated when the current record is empty). As you can see in the example below that generates HTML tables, each column is delimited by < TD >...</td >, each line is delimited by < TR >...</tr >. Let's take a look at the example code.
<%@ language= "VBSCRIPT"% >
<% Option Explicit ' good coding technique
' Establish connection to DB
Dim Conn
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "Dsn=northwind;"
' Create a recordset
Dim RS
Set rs = Server.CreateObject ("ADODB.") Recordset ")
Rs. Open "SELECT * FROM table1", Conn
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.