multiple recordsets
-
I want to display the 2 fields of all records in a table in listbox. my program is crshing. i dont know why. can someone help me? here is the code snippets.. BOOL CMgen1Doc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) if(m_mgen1Set == NULL) { m_mgen1Set = new CMgen1Set(&m_database); CString strConnect = m_mgen1Set->GetDefaultConnect(); m_database.Open(NULL, FALSE, FALSE, strConnect, FALSE); } return TRUE; } void CMgen1View::OnInitialUpdate() { m_pSet = GetDocument()->m_mgen1Set; CRecordView::OnInitialUpdate(); LoadListbox(); } void CMgen1View::LoadListbox() { CMgen1Doc* pDoc = GetDocument(); CListBox* pLB = (CListBox*) GetDlgItem(IDC_LIST1); CMgen1Set sect(&pDoc->m_database); sect.Open(); while(!sect.IsEOF()) { pLB->AddString(sect.m_CourseID + " " + sect.m_SectionNo); sect.MoveNext(); } }
-
I want to display the 2 fields of all records in a table in listbox. my program is crshing. i dont know why. can someone help me? here is the code snippets.. BOOL CMgen1Doc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) if(m_mgen1Set == NULL) { m_mgen1Set = new CMgen1Set(&m_database); CString strConnect = m_mgen1Set->GetDefaultConnect(); m_database.Open(NULL, FALSE, FALSE, strConnect, FALSE); } return TRUE; } void CMgen1View::OnInitialUpdate() { m_pSet = GetDocument()->m_mgen1Set; CRecordView::OnInitialUpdate(); LoadListbox(); } void CMgen1View::LoadListbox() { CMgen1Doc* pDoc = GetDocument(); CListBox* pLB = (CListBox*) GetDlgItem(IDC_LIST1); CMgen1Set sect(&pDoc->m_database); sect.Open(); while(!sect.IsEOF()) { pLB->AddString(sect.m_CourseID + " " + sect.m_SectionNo); sect.MoveNext(); } }
Usual questions: What do you mean by crashing? (e.g. Asserting in DEBUG mode, Gets Access violation etc.) Where is the program crashing? (Stepping through your code, what line is it executing when it "crashes" Are there any error indications? (ASSERT dialog, TRACE output, GPF dialog etc.) I don't see anything wrong with the code you presented off hand, but I won't look at it very closely until I know what I am looking for.
-
Usual questions: What do you mean by crashing? (e.g. Asserting in DEBUG mode, Gets Access violation etc.) Where is the program crashing? (Stepping through your code, what line is it executing when it "crashes" Are there any error indications? (ASSERT dialog, TRACE output, GPF dialog etc.) I don't see anything wrong with the code you presented off hand, but I won't look at it very closely until I know what I am looking for.
This is the message in the box: This program has performed an illegal operation and will be shutdown. If the problem persists contact the vendor. If I click the Details button i see the following msg: MGEN1 caused an invalid page fault in module at 00f9:000615c9. When I step through the code, I am getting an 'Unhandled exception' in this CRecordView::OnInitialUpdate(); line of code. void CMgen1View::OnInitialUpdate() { m_pSet = GetDocument()->m_mgen1Set; CRecordView::OnInitialUpdate(); LoadListbox(); }
-
This is the message in the box: This program has performed an illegal operation and will be shutdown. If the problem persists contact the vendor. If I click the Details button i see the following msg: MGEN1 caused an invalid page fault in module at 00f9:000615c9. When I step through the code, I am getting an 'Unhandled exception' in this CRecordView::OnInitialUpdate(); line of code. void CMgen1View::OnInitialUpdate() { m_pSet = GetDocument()->m_mgen1Set; CRecordView::OnInitialUpdate(); LoadListbox(); }
Hello! You cannot call the 'GetDocument()' function of a view before you call 'CRecordView::OnInitialUpdate()'. Your program crashes because GetDocument() does not know what to return. Let me quickly explain. The CRecordView::OnInitialUpdate function hooks your view into the document, so that you can always retreive the associated document with GetDocument(). If you try and call GetDocument() before that, it will probably return NULL, giving you an 'Unhandled exception' (trying to access something in a NULL pointer). So, you code should look something like this (minus the comments, of course, which just explain what I'm doing):
void CMgen1View::OnInitialUpdate()
{
//Always call this before calling GetDocument:
CRecordView::OnInitialUpdate();//Now the view is hooked to the document, so get the set: m\_pSet = GetDocument()->m\_mgen1Set; LoadListbox();
}
Hope that helps! Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem