If the query results are many, the server explains your ASP script will take a lot of time, because there are many
The Response.Write statement is 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 a lot faster. 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 are still using the previous version, please upgrade to the latest version)
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 recordset's results, we only care about 3 of the 5 parameters of GetString:
ColumnDelimiter (HTML code that separates the columns of the Recordset), RowDelimiter (the HTML code that separates the rows of the Recordset), and nullexpr (the HTML code that should be generated when the current record is empty). As you can see in the example below that generates an HTML table, each column is <TD >...</td > delimited, with <tr >...</tr > delimited for each row. 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
' Store our one big string '
Dim strtable
Strtable = Rs. GetString (,, "</td ><td >", </td ></tr ><tr ><td > "
," ")
%>
<HTML>
<BODY>
<TABLE>
<tr ><TD>
<% Response.Write (strtable)%>
</TR ></TD>
</TABLE>
</BODY>
</HTML>
<%
' cleanup!
Rs. Close
Set rs = Nothing
Conn. Close
Set conn = Nothing
%>
The strtable string is used to store the code for the HTML table we generated from the "SELECT * from table1" result.
There will be </td ><td > HTML code between each column of the HTML table, and the HTML code between each line is </td ></td ><tr ><td. The GetString method will output the correct HTML code and store it in strtable so that we can output all the records in the dataset in just one line Response.Write. Let's take a look at a simple example, assuming that our query results return the following rows and columns:
Col1 Col2 Col3
Row1 Bob Smith 40
Row1 Ed Frank 43
Row1 Sue Void 42
Then the string returned by the GetString statement will be:
BOB</TD ><td >smith</td ><td >40</td ><td ></td ></tr ><tr ><
Td
>ed ...