Using GetString to improve ASP speed _ Application Skills

Source: Internet
Author: User
<%
' Create Connection/recordset
' Populate data into Recordset object
%>
<TABLE>
<% do, not Rs. EOF%>
<TR>
&LT;TD ><%=rs ("Field1")% ></TD>
&LT;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 very long string (from), 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 HTML tables, each column uses [TD] ... [/td] delimited, each line with [TR] ... [/tr] Delimited. Examples of code:
The following is a reference fragment:
<%@ 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)%>
&LT;/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:
The following is a reference fragment:
Col1 Col2 Col3
Row1 Bob Smith 40
Row1 Ed Frank 43
Row1 Sue Void 42

The string returned by the GetString statement will be:
The following is a reference fragment:
BOB&LT;/TD ><td >smith</td ><td >40</td ><td ></td ></tr ><tr ><
Td
>ed ... BOB&LT;/TD ><td >smith</td ><td >40</td ><td ></td ></tr ><tr >< TD >ed ...

The string looks long and messy, but it's the HTML code you want. (Note that we're going to put it behind it in the hand-written HTML code.) This is because our formatted string does not contain the string required for the end of the table. )
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.