Microsoft KB Archive/153807

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

Article ID: 153807

Article Last Modified on 12/10/2003

-

APPLIES TO

 The DAO SDK, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Professional Edition 

-

<div class="notice_section">

This article was previously published under Q153807

<div class="symptoms_section">

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.

<div class="resolution_section">

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.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

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 query words: 4.00 4.10 4.20

Keywords: KB153807

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.