Using GetString to improve ASP running speed

Source: Internet
Author: User
Tags html form
Many ASP programmers have run database queries and then display the query results in HTML form
Go through it. That's what we usually do:
<%
' Createconnection/recordset
' Populatedataintorecordsetobject
%>
<table>
<%dowhilenotrs.eof%>
<tr>
<td><%=rs ("field1")%></td>
<td><%=rs ("Field2")%></td>
...
</tr>
<%rs.movenext
Loop%>
</table>
If the query results are many, the server explains that your aspscript 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 very long string (from
<table> to </table>), then the server only needs to explain the Response.Write statement, the speed will be faster
Many of the most capable guys in Microsoft have turned their ideas into reality. (Note that this is a ado2.0
. If you are still using ado1.5 words, you can
http://www.microsoft.com/data/download.htm free Download ado2.0)
With the GetString method, we can display all the output with just one Response.Write, and it
An image is a do...loop loop that can determine whether a recordset is EOF.
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 (the HTML code that separates the columns of the Recordset), RowDelimiter (that separates the rows of the Recordset)
HTML code), and nullexpr (the HTML code that should be generated when the current record is empty). It's like you're building underneath.
As you can see in the examples in HTML tables, each column is <td>...</td> delimited, with <tr>...</tr> points for each row
Let's take a look at the example code.
<% @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 (,, "</td><td>", "</td></tr><tr><td>", "&nbsp;") %
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.