Article ID: 153807
Article Last Modified on 12/10/2003
// 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