Why I can view only first 418 records from .MDB when using MS DataGrid+MS Adodc?
I have created a MFC project, based on Microsoft ADO Data Control and Microsoft
DataGrid Control to work with Microsoft Access databases. But when i connects Adodc to .MDB and binds with DataGrid,
there are only first 418 records from database table appears in the grid instead
of 600. Please, help me understand what's wrong here.
This is initialization function for Adodc (m_ctlADODC defined in CMyADODCViev
class as "public CAdodc m_ctlADODC;"):
---[cut]---
/////////////////////////////////////////////////////////////////////////////
// CMyADODCView message handlers
void CMyADODCView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
TCHAR szConnectionString[MAX_PATH+128]=_T("driver={Microsoft Access Driver (*.mdb)};dbq=");
TCHAR szErrMessage[512];
BOOL bSucceed=TRUE;
try {
// check if ADODC window was created
if (m_ctlADODC.m_hWnd==NULL) {
lstrcpy(szErrMessage,_T("Microsoft ADO Data Control window creation failed"));
AfxThrowUserException();
}
// try to close previous recordset
C_Recordset& rc=m_ctlADODC.GetRecordset();
if (rc.m_lpDispatch!=NULL) rc.Close();
// initialize data-source and set connection
m_ctlADODC.SetConnectionString(NULL);
lstrcat(szConnectionString,GetDocument()->GetPathName());
lstrcat(szConnectionString,_T(";"));
m_ctlADODC.SetConnectionString(szConnectionString);
m_ctlADODC.SetRecordSource(_T("[Radon Post Device database]"));
m_ctlADODC.SetCursorType(adOpenDynamic);
m_ctlADODC.SetLockType(adLockPessimistic);
m_ctlADODC.SetCommandType(adCmdTable);
m_ctlADODC.SetCaption(_T("Radon Post Database control"));
// if here an error with code DISP_E_EXCEPTION=0x80020009 occurs, check
// the Connection String for invalid value
m_ctlADODC.Refresh();
// process COM-component exception occurs
} catch (_com_error &e) {
lstrcpy(szErrMessage,e.ErrorMessage());
bSucceed=FALSE;
// process user-defined exceptions here
} catch(CUserException* e) {
bSucceed=FALSE;
// process if CException occurs
} catch(CException* e) {
e->GetErrorMessage(szErrMessage,sizeof(szErrMessage),NULL);
if (szErrMessage[0]==0) lstrcpy(szErrMessage,_T("Couldn't link Microsoft ADO Data Control to database."));
bSucceed=FALSE;
// process if unhandled exceptions
} catch (...) {
lstrcpy(szErrMessage,_T("Couldn't initialize Microsoft ADO Data Control: unknown exception."));
bSucceed=FALSE;
}
// check succeed status and output error if any exception occurs
if (!bSucceed) {
lstrcat(szErrMessage,"\nIf problem persists, try to reinstall "
"MDAC and this software on your computer.");
AfxMessageBox(szErrMessage,MB_ICONSTOP);
}
}
---[cut]---
And this is for DataGrid (m_pGrid defined in CMainFrame class as
"public: CDataGrid* m_pGrid;", it creates during CMainFrame initialization).
---[cut]---
/////////////////////////////////////////////////////////////////////////////
// CMyDataGridView message handlers
void CMyDataGridView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
TCHAR szErrMessage[512];
BOOL bSucceed=TRUE;
m_pMainFrame=reinterpret_cast<CMainFrame*>(AfxGetMainWnd());
try {
// TODO: Add your specialized creation code here
// create DataGrid data-bind control
if (m_pMainFrame->m_pGrid->m_hWnd==NULL) {
if (!m_pMainFrame->m_pGrid->Create(NULL,_T("(c) 2002 by Dmitry Petrenko"),WS_CHILD|WS_VISIBLE,CRect(2,2,GRID_DEF_WIDTH+2,GRID_DEF_HEIGHT+2),
this,IDC_DBGRID1)) {
// TODO: Add here error handling
lstrcpy(szErrMessage,_T("Microsoft DataGrid Control window creation failed"));
AfxThrowUserException();
}
}
// get reference at ADO data-source control
CAdodc& refADO=m_pMainFrame->GetBottomPane()->m_ctlADODC;
if (refADO.m_hWnd!=NULL) {
m_pMainFrame->m_pGrid->SetRefDataSource(NULL);
m_pMainFrame->m_pGrid->SetRefDataSource(refADO.GetRecordset());
m_pMainFrame->m_pGrid->SetAllowAddNew(TRUE); // allow empty '*'-field at top
m_pMainFrame->m_pGrid->SetAllowUpdate(TRUE); // allow editing current records
m_pMainFrame->m_pGrid->SetAllowDelete(TRUE); // allow deleting by pressing Del (???)
m_pMainFrame->m_pGrid->SetAllowArrows(TRUE); // allow arrows keys (???)
m_pMainFrame->m_pGrid->Refresh();
m_pMainFrame->m_pGrid->UpdateData();
}
// process COM-component exception occurs
} catch (_com_error &e) {
lstrcpy(szErrMessage,e.ErrorMessage());
bSucceed=FALSE;
// process user-defined exceptions here
} catch(CUserException* e) {
// process if CException occurs
bSucceed=FALSE;
} catch(CException* e) {
e->GetErrorMessage(szErrMessage,sizeof(szErrMessage),NULL);
if (szErrMessage[0]==0) lstrcpy(szErrMessage,_T("Couldn't link Microsoft DataGrid Control to database."));
bSucceed=FALSE;
// process if unhandled exceptions
} catch (...) {
lstrcpy(szErrMessage,_T("Couldn't initialize Microsoft DataGrid Control: unknown exception."));
bSucceed=FALSE;
}
// check succeed status and output error if any exception occurs
if (!bSucceed) {
lstrcat(szErrMessage,"\nIf problem persists, try to reinstall MDAC and this "
"software on your computer.");
AfxMessageBox(szErrMessage,MB_ICONSTOP);
}
}
---[cut]---