WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

ADO Speed Up With GetString()


Use the GetString() strategy to accelerate your ASP content of utilizing various Response.Write's).


Multiple Response.Write's

The following precedent shows one method for how to show a database question in a HTML table:

<html>
<body>

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"

set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT Companyname, Contactname FROM Customers", conn
%>

<table border="1" width="100%">
<%do until rs.EOF%>
  <tr>
    <td><%Response.Write(rs.fields("Companyname"))%></td>
    <td><%Response.Write(rs.fields("Contactname"))%></td>
  </tr>
<%rs.MoveNext
loop%>
</table>

<%
rs.close
conn.close
set rs = Nothing
set conn = Nothing
%>

</body>
</html>

For a vast inquiry, this can back off the content preparing time, since numerous Response.Write directions must be prepared by the server.

The arrangement is to have the whole string made, from <table> to </table>, furthermore, at that point yield it - utilizing Response.Write just once.


The GetString() Method

The GetString() technique enables you to show the string with just a single Response.Write. It additionally wipes out the do...loop code and the restrictive test that checks if the recordset is at EOF.

Syntax

str = rs.GetString(format,rows,coldel,rowdel,nullexpr)

To make a HTML table with information from a recordset, we just need to utilize three of the parameters above (all parameters are optional):

  • coldel - the HTML to use as a section separator
  • rowdel - the HTML to use as a line separator
  • nullexpr - the HTML to utilize if a segment is NULL

Note: The GetString() strategy is an ADO 2.0 component. You can download ADO 2.0 at http://www.microsoft.com/information/download.htm.

In the accompanying model we will utilize the GetString() technique to hold the recordset as a string:

Example

<html>
<body>

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"

set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT Companyname, Contactname FROM Customers", conn

str=rs.GetString(,,"</td><td>","</td></tr><tr><td>","&nbsp;")
%>

<table border="1" width="100%">
  <tr>
    <td><%Response.Write(str)%></td>
  </tr>
</table>

<%
rs.close
conn.close
set rs = Nothing
set conn = Nothing
%>
</body>
</html>

Show precedent »

The str variable above contains a string of the considerable number of sections and lines returned by the SQL SELECT explanation. Between each segment the HTML </td><td> will show up, and between each column, the HTML </td></tr><tr><td> will show up. This will deliver the precise HTML we need with just a single Response.Write.