Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 272165 - Last Review: July 13, 2004 - Revision: 3.2
How To Use a Singleton SELECT from ASP
This article was previously published under Q272165
This article demonstrates the use of a singleton SELECT to retrieve a single record from the SQL Server IRow interface from ASP.
A singleton SELECT speeds data retrieval for a resultset that contains one record. The speed increase is a direct result of removing the overhead required for creating the recordset. However, because no recordset is actually created, only one read-only ADODB.Record is returned. This is true regardless of whether the specified SELECT results in multiple records being returned.
If the desired result set contains more than one record, then a normal recordset can be used. Therefore, it is not advisable to issue multiple singleton SELECTs as an alternative to opening a normal ADODB.Recordset in anticipation of retrieving the results faster. The buffering and caching that are set up for a normal ADODB.Recordset speed the performance when you want to retrieve multiple records.
<%@ Language=VBScript %>
<!--#include file="adovbs.inc" -->
<%
Dim adoConn ' As ADODB.Connection
Dim adoRec ' As ADODB.Record
Dim sConn ' As String
Dim sQuery ' As String
Dim col ' As ADODB.Field
dim txtResults ' output string for results
set adoConn = CreateObject("ADODB.Connection")
adoConn.ConnectionString = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Northwind;uid=sa;pwd=;"
adoConn.CursorLocation = adUseServer
adoConn.Open
sQuery = "SELECT * FROM CUSTOMERS WHERE CUSTOMERID='ALFKI'"
Set adoRec = CreateObject("ADODB.Record")
adoRec.Open sQuery, adoConn, adModeRead, ,adOpenExecuteCommand
Response.write("<table><thead><th align=left>Column Name</th><th align=left>Column Value</th></thead>" )
For Each col In adoRec.Fields
Response.Write ("<tr><td align=left>" & col.Name & "</td><td align=left>" & col.Value & "</td></tr>" )
Next
Response.Write ( "</table>")
%>
APPLIES TO
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.5 Service Pack 1
- Microsoft Data Access Components 2.6
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate