ADO Beginner's Tutorial: ADO through GetString () acceleration Script

Source: Internet
Author: User
Tags query string

Author: Please use the GetString () method to speed up your ASP script (to replace multiple rows of Response.Write).

Instance

Using GetString ()

How to use GetString () to display data in a recordset in an HTML table.

Multi-line Response.Write

The following example shows one way to display a database query in an HTML table:

The following are the referenced contents:

<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>

For a large query, this increases the processing time for the script, because the server needs to handle a large number of Response.Write commands.

The solution is to create all the strings, from <table> to </table>, and then output them-using only once Response.Write.

GetString () method

The GetString () method gives us the ability to display all strings using only one Response.Write at a time. And it doesn't even need do. Loop code and conditional tests to check whether the recordset is in EOF.

Grammar

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

To create an HTML table using data from a recordset, we only need to use three of the above parameters (all of the parameters are optional):

Coldel-HTML used as a column separator

Rowdel-HTML used as a row delimiter

NULLEXPR-HTML used when column is empty

Note: the GetString () method is an attribute of ADO 2.0. You can download the ADO 2.0:http://www.microsoft.com/data/download.htm from the address below

In the following example, we will use the GetString () method to save the recordset as a string:

The following are the referenced contents:

<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>", "")
%>
<table border= "1" width= "100%" >
<tr>
<td><%response.write (str)%></td>
</tr>
</table>
<%
Rs.close
Conn.close
Set rs = Nothing
Set conn = Nothing
%>
</body>

The above variable str contains a string of all columns and rows returned by the SELECT statement. </td><td> appears between each column, </td></tr><tr><td> appears between each row. So, with only one Response.Write, we get the HTML we need.



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.