CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    May 2007
    Posts
    25

    Question How to delete data using ADO ?

    I am not able to delete data using ADO ,Will you please help me ?
    Code I written as follows
    Code:
    #include <iostream>
    #include <tchar.h>
    #import " C:/Program Files/Common Files/System/ado/msado15.dll"  \
         rename( "EOF", "AdoNSEOF" )
     
        _bstr_t bstrConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\\VCPrograms\\Other Trials\\Database2.accdb;";
         HRESULT hResult = CoInitialize( 0 );
        if( FAILED( hResult ))
        {
            return;
        }
        try
        {
    	 ADODB::_ConnectionPtr pConnect("ADODB.Connection");
            hResult = pConnect->Open( bstrConnect, "admin", "",    
                      ADODB::adConnectUnspecified );
            if (SUCCEEDED(hResult))
            {
    	   _bstr_t query = "SELECT * FROM Table1 WHERE EmpId = 1;";
                ADODB::_RecordsetPtr pRecSet( "ADODB.Recordset" );
                hResult = pRecSet->Open( query, _variant_t((IDispatch *) pConnect, true), ADODB::adOpenUnspecified,ADODB::adLockUnspecified, ADODB::adCmdText);
    	    if( SUCCEEDED( hResult ))
               {
    	            pRecSet->Delete(ADODB::adAffectCurrent);
    	           pRecSet->UpdateBatch(ADODB::adAffectCurrent);
    	    }
                 pRecSet->Close();
                pConnect->Close();
    	}
        }
        catch( _com_error& e )
        {
            // Handle Exception
        }
     
        // Release COM
        CoUninitialize();
    }
    Last edited by shivditya; April 2nd, 2012 at 10:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured