Adovcbtd.exe #import Using UpdateBatch and CancelBatch

This article was previously published under Q181733
This article has been archived. It is offered "as is" and will no longer be updated.
The Adovcbtd.exe sample demonstrates CancelBatch, UpdateBatch, AddNew,Delete, Move, and other ActiveX Data Objects (ADO) Recordset methods usingsmart pointers and #import. Using #import is the preferred way for VisualC++ programmers to use ADO.

The program is written and designed to demonstrate how to get started withADO via #import.
The following file is available for download from the Microsoft Download Center:
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 sample undefines EOF in Stdafx.h to prevent a conflict. The followingthree lines are from the Stdafx.h file:

   #undef EOF   #import <Msado15.dll> rename_namespace("ado15")   //  Please see the #import Directive help in InfoViewer   rename_namespace("ado15")				

Msado15.dll has to be located on the same drive as the Windows Systemdirectory, and in a path \program files\common files\system\ado. You canconfigure Visual C++ to use this path to search for the ADO .dll,eliminating the need to specify the explicit path within your #importstatement, just as you would configure the location of header files used by
#include. The sample renames the namespace to prevent collisions with other				
COM libraries.

The sample shows what ADO capabilities are supported by the driver and alsouses a Microsoft Access database. However, you can replace it withother data sources in the code.

With certain combinations of Delete/Add New/Next/Prev, it is possible toget an OLE error. The code is provided as a sample only and is not forproduction purposes.

NOTE: You cannot pass a connection object in the recordset Open methodin ADO version 1.5. You must use the PutRefActiveConnection method. Thisdiffers from ADO 1.0 and Visual Basic (VB). The following code shows how to open a recordset using an ODBC Data Source Name (DSN). The sample file opens the recordset using an alternate (DSN-less) method. Note that error checking has been omitted for clarity in the code given below, but isincluded in the sample file.

Here is the code:

   void CAdxDlg::OnBUTopen()   {      _ConnectionPtr  Conn1;      HRESULT hr=Conn1.CreateInstance( __uuidof( Connection ) );      _bstr_t bsDSN   = (L"Student Registration");      _bstr_t bsEmpty = L"";      Conn1->ConnectionString = bsDSN;      Conn1->Open( bsEmpty, bsEmpty, bsEmpty, -1 );      hr=Rs1.CreateInstance( __uuidof( Recordset ) );      Rs1->PutRefActiveConnection( Conn1 );      _bstr_t bsSel(L"SELECT * FROM Student");      Rs1->Open(bsSel,vtMissing,adOpenKeyset,adLockBatchOptimistic,-1);   }				

For additional information about running the sample file, please refer tothe Readme.txt file included with the sample.
For additional information on using ADO with #import, please see thefollowing articles in the Microsoft Knowledge Base:For additional information184968, click the article numberFILE: Adovcsp.exe Demonstrates Using Stored Procedures with ADO below to view the articleFILE: Adovcsp.exe Demonstrates Using Stored Procedures with ADO in the Microsoft Knowledge Base:
%3 %4
220152 FILE: Sample: ADOVC1 Simple ADO/VC++ Application
200122 SAMPLE: ATL2ADO Returns disconnected recordset from COM to VB
229088 SAMPLE: Vcspnp.exe Demonstrates Passing SQL NULL Parameters and Reading NULL Values with ADO

ADOVCBTD CancelUpdate _com_error MoveNext MoveLast CancelBatch adAffectAll Supports Delete

Article ID: 181733 - Last Review: 02/24/2014 08:32:25 - Revision: 3.3

Microsoft ActiveX Data Objects 1.5, Microsoft ActiveX Data Objects 2.6, Microsoft ActiveX Data Objects 2.7

  • kbnosurvey kbarchive kbdownload kbdatabase kbfile kbinfo KB181733