Article ID: 153216
Article Last Modified on 12/2/2003
#define FETCH_SIZE 2
#define MAX_FIRST_NAME_LENGTH 20
// Perform C++ GetRowsEx against the Employee table
void CGetRowsDlg::DoGetRowsEx()
{
LPEMP pEmpRows = new EMP[FETCH_SIZE];
CListBox *pListBox = (CListBox*)GetDlgItem(IDD_GETROWSLISTEX);
CString strLBRow;
TCHAR szId[16];
LONG lNumRecords;
LONG lCount;
TCHAR pBuf[MAX_EMP_REC * 15]; // allow avg of 15 chars/name
while (!m_cEmpRecordSet.GetEOF())
{
//Clear values in buffer for variable-length fields
for (long lCnt = 0; lCnt < FETCH_SIZE; lCnt++)
{
_strnset(pEmpRows[lCnt].strFirstName,'\0',
MAX_FIRST_NAME_LENGTH);
pEmpRows[lCnt].strLastName=NULL;
}
try
{
lNumRecords = m_cEmpRecordSet.GetRowsEx(pEmpRows, sizeof(EMP),
&Bindings[0], sizeof(Bindings) /
sizeof(DAORSETBINDING),
pBuf, sizeof(pBuf),
FETCH_SIZE);
}
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;
if (pEmpRows[lCount].strLastName!=NULL)
strLBRow += pEmpRows[lCount].strLastName;
else
strLBRow += "null";
strLBRow += _T(", ");
if (pEmpRows[lCount].strFirstName[0]=='\0')
strLBRow += "null";
else
strLBRow += (LPCTSTR) pEmpRows[lCount].strFirstName;
pListBox->AddString(strLBRow);
}
if (!m_cEmpRecordSet.GetEOF())
m_cEmpRecordSet.MoveNext(); // Need to move to next unread
// record before fetching the next
// set of records.
}
delete [] pEmpRows;
}
Additional query words: kbVC400bug 4.00 4.10 4.20
Keywords: KB153216