Ralph_Brickley
October 19th, 2004, 08:44 PM
I'm just learning to use CDatabase and CRecordSet for a simple database program and I had it working fine. I derived a class, CServantSet from CRecordSet and all that was working fine. In a day I learned to open the database, open the record set, run queries and update data.
Now I'm looking to AddNew. I made a seperate Dialogue class for the Add New screen but that is not in use right now so it shouldn't make a difference.
However, after doing so, I am now getting the Out of Memory error on the beginning portion of my program which doesn't make any sense. The Open and following function calls have not changed but the error is coming from ->Open();
if(!m_DB.OpenEx("DSN=MySQL ODBC;DATABASE=ServantManager;SERVER=localhost;", CDatabase::noOdbcDialog))
{
m_Text += "Error Opening Database\r\n";
UpdateData(FALSE);
return;
}
if(!m_ServantSet)
m_ServantSet = new CServantSet(&m_DB);
...
m_ServantSet->m_strSort = "Last, First";
m_Text += "Peform Open\r\n";
UpdateData(FALSE);
m_ServantSet->Open(AFX_DB_USE_DEFAULT_TYPE, "SELECT * FROM PeopleProfile", CRecordset::noDirtyFieldCheck);
m_Text += "Open. IsEOF?\r\n";
UpdateData(FALSE);
if(!m_ServantSet->IsEOF())
{
MessageBox("GetRecordCount()");
long count = m_ServantSet->GetRecordCount();
if(count > 0)
{
// Fetch data...
char msg[50];
wsprintf(msg, "Records Found: %d\r\n", count);
m_Text = msg;
UpdateData(FALSE);
m_Text += m_ServantSet->m_First;
MessageBox("MoveNext()");
m_ServantSet->MoveNext();
}
}
else
{
m_ServantSet->Close();
m_Text = "There were no records found.\r\n";
}
UpdateData(FALSE);
m_ServantSet->Close();
Does anyone have an idea what the problem could be? Thanks for any advice!!
Now I'm looking to AddNew. I made a seperate Dialogue class for the Add New screen but that is not in use right now so it shouldn't make a difference.
However, after doing so, I am now getting the Out of Memory error on the beginning portion of my program which doesn't make any sense. The Open and following function calls have not changed but the error is coming from ->Open();
if(!m_DB.OpenEx("DSN=MySQL ODBC;DATABASE=ServantManager;SERVER=localhost;", CDatabase::noOdbcDialog))
{
m_Text += "Error Opening Database\r\n";
UpdateData(FALSE);
return;
}
if(!m_ServantSet)
m_ServantSet = new CServantSet(&m_DB);
...
m_ServantSet->m_strSort = "Last, First";
m_Text += "Peform Open\r\n";
UpdateData(FALSE);
m_ServantSet->Open(AFX_DB_USE_DEFAULT_TYPE, "SELECT * FROM PeopleProfile", CRecordset::noDirtyFieldCheck);
m_Text += "Open. IsEOF?\r\n";
UpdateData(FALSE);
if(!m_ServantSet->IsEOF())
{
MessageBox("GetRecordCount()");
long count = m_ServantSet->GetRecordCount();
if(count > 0)
{
// Fetch data...
char msg[50];
wsprintf(msg, "Records Found: %d\r\n", count);
m_Text = msg;
UpdateData(FALSE);
m_Text += m_ServantSet->m_First;
MessageBox("MoveNext()");
m_ServantSet->MoveNext();
}
}
else
{
m_ServantSet->Close();
m_Text = "There were no records found.\r\n";
}
UpdateData(FALSE);
m_ServantSet->Close();
Does anyone have an idea what the problem could be? Thanks for any advice!!