Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

SAMPLE: How to Run Singleton SELECT Queries in Visual C++


View products that this article applies to.

This article was previously published under Q272176

↑ Back to the top


Summary

STonSel.exe demonstrates how to configure an ADO 2.6 client to retrieve one row of data from a SQL Server 2000 database.

↑ Back to the top


More information

The following file is available for download from the Microsoft Download Center:
Release Date: 9-29-2000

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591� How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. The STonSel.exe file contains the following files:

Collapse this tableExpand this table
File nameSize
EULA.txt2 KB
STonSel.cpp5 KB



The ADO Record object in ADO 2.6 has been enhanced to support the retrieval of a single Record. The data obtained is read-only. In case the query results in more than one record, only the first record encountered is returned. The sample performs the following to retrieve one single record:
  1. Sets up a connection to a SQL Server 2000 database:
    _bstr_t m_Conn("PROVIDER=SQLOLEDB.1;SQL2000Server=Server;Database=Northwind;uid=sa;pwd=;");
    hr = conn->Open(m_Conn,L"",L"",-1);
    					
  2. Sets up the ADO Record to contain the query:
    hr = rec->put_Source(L"SELECT * FROM CUSTOMERS WHERE CUSTOMERID='ALFKI'");
    					
  3. Opens the Record object by using the adExecuteCommand enumeration:
    hr = rec->Open(vtEmpty,vtEmpty,adModeReadWrite,adFailIfNotExists, adOpenExecuteCommand,L"",L"");
    					

Steps to Run the Sample

  1. Create an empty Win32 console application.
  2. Insert STonSel.cpp into the project.
  3. Modify the connection string to refer to a valid SQL Server 2000 database.
  4. Compile and then run the application.

↑ Back to the top


Keywords: KB272176, kbinfo, kbfile, kbcodesnippet, kbdownload

↑ Back to the top

Article Info
Article ID : 272176
Revision : 8
Created on : 8/5/2004
Published on : 8/5/2004
Exists online : False
Views : 241