PRB: GetRowsEx Re-fetches Last Read Record in Subsequent Calls

Last reviewed: August 7, 1997
Article ID: Q153807
4.00 4.10 4.20 WINDOWS NT kbprg kbprb

The information in this article applies to:

  • The DAO SDK included with:

        - Visual C++, versions 4.0, 4.1, 4.2
    

SYMPTOMS

The DAO SDK defines a function called GetRowsEx() that is a method of the DAO recordset object. Unlike the GetRows() method, the GetRowsEx() method does not advance to the next unread record after calling it. Instead, it begins fetching with the last record fetched or the current record. For example, if you have 10 records in a resultset and you are fetching 5 of them at a time using GetRowsEx(), you will see that record #5 gets fetched twice, once for each GetRowsEx() call. Records 1 through 5 will be fetched in the first call to GetRowsEx() and records 5 through 10 will be fetched in the second call to GetRowsEx().

RESOLUTION

Call MoveNext() for the recordset before executing the next call to GetRowsEx(). The MoveNext() call will make the next unread record the current record.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Problem

Modify the DoGetRowsEx() function in GETRDLG.CPP contained in the GETROWS DAO SDK sample. Change the code to the following:

   // Perform C++ GetRowsEx against the Employee table
   void CGetRowsDlg::DoGetRowsEx()
   {
       LPEMP           pEmpRows = new EMP[MAX_EMP_REC];
       CListBox        *pListBox =
                        (CListBox *)GetDlgItem(IDD_GETROWSLISTEX);
       CString         strLBRow;
       TCHAR           szId[16];
       LONG            lNumRecords;
       LONG            lCount;
       TCHAR           pBuf[MAX_EMP_REC * 15];

       //Perform GetRows on Employee table
       //This GetRows uses a specific C++ structure
       while (!m_cEmpRecordSet.GetEOF())
       {
       try
           {
           lNumRecords = m_cEmpRecordSet.GetRowsEx(pEmpRows, sizeof(EMP),
                 &Bindings[0], sizeof(Bindings) / sizeof(DAORSETBINDING),
                           pBuf, sizeof(pBuf),
                           2); // fetch 2 records at a time
           }
       catch (CdbException e)
           {
        //Differentiate between GetRowsEx Errors and other CdbExceptions
        // see defines in DAOGETRW.H
           if( e.m_hr == E_ROWTOOSHORT ||
               e.m_hr == E_BADBINDINFO ||
               e.m_hr == E_COLUMNUNAVAILABLE )
               {
               AfxMessageBox(_T("Error in GetRowsEx call."));
               }
           else
               {
               AfxMessageBox(_T("General CdbException"));
               }
           delete [] pEmpRows;
           return;
           }

       //Step through the returned rows
       for (lCount = 0; lCount < lNumRecords; lCount++)
           {
           strLBRow.Empty();
           wsprintf(szId, _T("%d,  "), pEmpRows[lCount].lEmpId);
           strLBRow += szId;
           strLBRow += pEmpRows[lCount].strLastName;
           strLBRow += _T(", ");
           strLBRow += (LPCTSTR) pEmpRows[lCount].strFirstName;
           pListBox->AddString(strLBRow);
           }
       }
       delete [] pEmpRows;
   }

To fix the code above, add a MoveNext at the end of the 'while' loop.


Additional reference words: 4.00 4.10 4.20
KBCategory: kbprg kbprb
KBSubcategory: dbDao
Keywords : dbDao kbprb kbprg
Version : 4.00 4.10 4.20
Platform : NT WINDOWS


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: August 7, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.