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



The information in this article applies to:

  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
  • Microsoft SQL Server 2000 (all editions)

This article was previously published under Q272176

SUMMARY

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

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:

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.

Modification Type:MinorLast Reviewed:8/5/2004
Keywords:kbdownload kbCodeSnippet kbfile kbinfo KB272176 kbAudDeveloper