Recommended: Use the ASP program to generate image format for phone numbers on the page Function: Use the ASP program to generate image format for phone numbers in the page. The following is the referenced fragment: The following is the referenced content: %Call Com_CreatValidCode(Reques
Many ASP programmers have had the experience of executing database queries and then displaying the query results in HTML tables. Usually we do this:
The following is the quoted content:
<%
'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 take a lot of time to explain your ASP script, because there are many
Response.Write statements need to be processed. If you put all the output results in a very long string (from <TABLE> to </TABLE>), the server only needs to explain the Response.Write statements, and the speed will be much faster. Some capable guys at Microsoft have turned their ideas into reality. (Note, this is a feature that only ADO 2.0 or above. If you are still using the previous version, please upgrade to the latest version)
With the GetString method, we can use only one Response.Write to display all outputs, which is like a DO...LOOP loop that can determine whether the Recordset is EOF.
The usage of GetString is as follows (all parameters are optional):
The following is the quoted content:
String = recordset.GetString(StringFormat,
NumRows,
ColumnDelimiter,
RowDelimiter, NullExpr)
To generate an HTML table from the Recordset result, we only need to care about 3 of the 5 parameters of GetString:
ColumnDelimiter (HTML code that separates columns in the record set), RowDelimiter (HTML code that separates rows in the record set), and NullExpr (HTML code that should be generated when the current record is empty). As you can see in the example of generating HTML table below, each column is separated by <TD >...</TD > and each row is separated by <TR >...</TR >. Let's take a look at the code for the example.
The following is the quoted content:
<%@ 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 generate 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 row is </td ></td ><tr ><td >. The GetString method outputs the correct HTML code and stores it in strTable, so that we only need one line of Response.Write to output all records in the dataset. Let's take a look at a simple example, assuming that our query results return the following rows and columns:
The following is the quoted content:
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:
The following is the quoted content:
Bob</td ><td >Smith</td ><td >40</td ><td ></td ></td ></tr ><tr ><
td
>Ed ...
To be honest, this string looks verbose and messy, but it is the HTML code we want. (Note that in the handwritten HTML code, we put <TABLE ><TR ><TD > in front of Response.Write and </TD ></TR ></TABLE > behind it. This is because our formatted string does not contain the strings required for the beginning and end of these tables.)
Share: How to implement rar compression and decompression of source code in Asp Asp implements rar compression and decompression of source code, and can be done with just one file. Asp compresses directories or files, decompresses rar files, deletes specific files and other functions. This source code is convenient for everyone to develop secondary and share it. The following is winrar.asp code: