<%
'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 will take a lot of time to explain your ASPscript, because there are many Response.Write statements to process. If you put all the output results in a very long string (from to), the server will just interpret the Response.Write statements and it will be much faster. Some capable guys at Microsoft have turned their ideas into reality. (Note, this is a feature that only ADO2.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):
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 of the record set), RowDelimiter (HTML code that separates rows of 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]. Example code:
The following is a quoted snippet:
<%@LANGUAGE="VBSCRIPT"%>
<%OptionExplicit'Goodcodingtechnique
'EstablishconnectiontoDB
Dimconn
Setconn=Server.CreateObject("ADODB.Connection")
conn.Open"DSN=Northwind;"
'Createacordset
Dimrs
Setrs=Server.CreateObject("ADODB.Recordset")
rs.Open"Select*FROMtable1", conn
'Storeouronebigstring
DimstrTable
strTable=rs.GetString(,, "</td><td>", "</td></tr><tr><td>" , "")
%>
<HTML>
<BODY>
<TABLE>
<TR><TD>
<%Response.Write(strTable)%>
</TR></TD>
</TABLE>
</BODY>