FILE: Adovcbtd.exe #import Using UpdateBatch and CancelBatch

Last reviewed: March 5, 1998
Article ID: Q181733
The information in this article applies to:
  • ActiveX Data Objects (ADO), version 1.5 included with:

        - Microsoft Visual C++, 32-bit Editions, version 5.0
    

SUMMARY

The Adovcbtd.exe sample demonstrates CancelBatch, UpdateBatch, AddNew, Delete, Move, and other ActiveX Data Objects (ADO) Recordset methods using smart pointers and #import. Using #import is the preferred way for Visual C++ programmers to use ADO.

The program is written and designed to demonstrate how to get started with ADO via #import.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ Adovcbtd.exe (size: 90008 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

The sample undefines EOF in Stdafx.h to prevent a conflict. The following three lines are from the Stdafx.h file:

   #undef EOF
   #import "C:\Program Files\Common Files\System\ADO\msado15.dll"
   rename_namespace("ado15")

Note that your ADO .dll files may be in different location so you will have to use the correct path for your computer. The sample renames the namespace to prevent collisions with other COM libraries.

The sample also shows what ADO capabilities are supported by the driver. The sample uses a Microsoft Access database but you can replace it with other data sources in the code.

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

Note that you cannot pass a connection object in the recordset Open method in ADO version 1.5. You must use the PutRefActiveConnection method. This differs 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 is included 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 to the Readme.txt file included with the sample.

REFERENCES

For additional information on using ADO with #import, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q169498
   TITLE     : INFO: Extracting Error Information from ADO in C++ with
               #import

   ARTICLE-ID: Q174565
   TITLE     : FILE: Adovc.exe Demonstrates How to Use ADO with Visual C++

   ARTICLE-ID: Q177939
   TITLE     : INFO: Changes in ADO 1.5 That Affect Visual C++/J++
               Programmers


Additional query words: CancelUpdate _com_error MoveNext MoveLast
CancelBatch adAffectAll Supports Delete
Keywords : kbfile adovc
Technology : ole
Version : WINDOWS:1.5
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.