Microsoft Knowledge Base Email Alertz

(272165) - This article demonstrates the use of a singleton SELECT to retrieve a single record from the SQL Server IRow interface from ASP.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











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

SUMMARY

This article demonstrates the use of a singleton SELECT to retrieve a single record from the SQL Server IRow interface from ASP.

MORE INFORMATION

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
Keywords: 
kbhowto KB272165
       

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