none
How to delete records in joined tables of MS Access using ADO OLEDB 4.0 Engine? RRS feed

  • Question

  • Hi All,

    Long time ago, I wrote an application using VC++ 6.0 and ADO to read and write MS access database. The MS Access97 database had two tables. Table 1 and Table 2 had same primary key. A query was established with Table 1 and Table 2 joined.

    Everything works fine. The application can open the query and delete records in both Table 1 and Table 2 with ADO delete method. 

    Since access97 was obsolete, now I use VC++.net 2003 and Access 2000. But I found that only records in Table 1 were deleted. The same records in Table 2 were not deleted at all.

    I used VC++.net 2003 and Access 2000.

    Here is my code.
     
         CoInitialize(NULL);
         _ConnectionPtr pConn = NULL;
         _RecordsetPtr pRecordset = NULL;
     
         pConn.CreateInstance(__uuidof(Connection));
         pConn->Open(_bstr_t("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\ADOTest.mdb"), "","", adModeUnknown);
         pRecordset.CreateInstance(__uuidof(Recordset));
         pRecordset->Open(_bstr_t("SELECT * FROM query1"), pConn.GetInterfacePtr(), adOpenStatic, 
                               adLockOptimistic, adCmdText);

         pRecordset->Delete(adAffectCurrent);
         pRecordset->Update();
         pRecordset->Close();
         pConn->Close();
         CoUninitialize();

    But if I used Access 97 and VC6 and changed pConn to:

         pConn->Open(_bstr_t("Provider = Microsoft.Jet.OLEDB.3.51; Data Source = C:\\ADOTest.mdb"), "","", adModeUnknown);
     
    Evertthing works.

    I cann't figure out what wrong with the code. Does anybody know How to delete records in joined tables of MS Access using ADO OLEDB 4.0 Engine?

    Thanks a lot.

    • Moved by Yan-Fei Wei Monday, August 11, 2008 1:30 AM an ADO issue (Moved from Visual C++ General to Off-Topic Posts (Do Not Post Here))
    Saturday, August 2, 2008 6:19 PM

All replies