Find a website from a foreign country (using GetString to improve the speed of ASP) I've tested it, it's a lot faster.

Source: Internet
Author: User
Tags html form
Speed Many ASP programmers have run database queries and then display the results of the query in an HTML form
Come through the
Calendar Bar. That's what we usually do:

<%
"Create Connection/recordset
"Populate data into the 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 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 >), then the server only needs to explain the Response.Write statement, the speed will
Much faster.
. Some of the most capable guys in Microsoft have turned their ideas into reality. (Note that this is an ADO 2.)
Only 0
The characteristics. If you are still using ADO 1.5 words, you can
http://www.microsoft.com/data/download.htm free download ADO 2.0)

With the GetString method, we can display all the output with just one Response.Write, which
Just like
is a do ... that can determine whether 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 need to 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 HTML underneath.
of the table
As you can see in the example, each column is separated by < TD >...</td >, each line with < TR >...</tr >
Come on.
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 >
<%

"Cleanup!
Rs. Close
Set rs = Nothing
Conn. Close
Set conn = Nothing
% >

The strtable string is used to store the HTML table that we generated from the "SELECT * from table1" result.
Code.
HTML tables will have </TD >< td > HTML code between each column, and the HTML code between each line is <
/TD ><
/TD >< TR >< TD. The GetString method will output the correct HTML code and be stored in the strtable
, so
We can output all the records in the dataset with just one line Response.Write. Let's take a look at Jane.
Example of a single
Son, suppose 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 ...

To be honest, the string looks long and messy, but it's the HTML code we want. (Watch out,
We are
In hand-written HTML code, < TABLE >< TR >< TD > is placed in front of the Response.Write to
</td
></tr ></table > put it in the back. This is because our formatted string does not contain this
Some forms
The string required for the tail.)



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.