我有一些从 MS Access 数据库中读取的代码。该代码如下:
CDatabase database;
CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString sDsn;
CString sFile = "MyDB.mdb";
CString sField;
// Build ODBC connection string
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s", sDriver, sFile);
TRY
{
// Open the database
database.Open(NULL, false, false, sDsn);
// Allocate the recordset
CRecordset recset(&database);
// Execute the query
recset.Open(CRecordset::forwardOnly, "SELECT NAME FROM INFOTABLE", CRecordset::readOnly);
// Loop through each record
while( !recset.IsEOF() )
{
// Copy each column into a variable
recset.GetFieldValue("NAME", sField);
// Add the obtained field to a drop-down box
m_dropDown.AddString(sField);
// goto next record
recset.MoveNext();
}
// Close the database
database.Close();
}
CATCH(CDBException, e)
{
// If a database exception occured, show error msg
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
我的问题是,有时会抛出异常。消息框显示,
Database error: Record too large
我的数据库有 > 30000 条记录。
为什么会出现这个异常?另外,为什么有时会出现?
谢谢!