I can't retrieve the data from my "file.mdb" file. Below is the code I created:

code = m_Code.Mid(beginIndex, endIndex);
CDaoDatabase database;
CDaoRecordset recordset(&database);
CString lpszFile = "C:/file.mdb";
database.Open(lpszFile, FALSE, TRUE, _T(""));
recordset.Open(AFX_DAO_USE_DEFAULT_TYPE,"SELECT * FROM KeyID", 0);
COleVariant olevar;
while(!recordset.IsEOF());
{
olevar.ChangeType(VT_BSTR, NULL);
recordset.GetFieldValue("ID", olevar);
CString fieldValue = (LPCSTR)olevar.pbstrVal;
if(code == fieldValue)
{
AfxMessageBox(fieldValue);
}
recordset.MoveNext();
}

The code I've created doesn't work. Can anyone please review my codes? I think there's something wrong with my codes. Thanks.

The code I've created doesn't work. Can anyone please review my codes? I think there's something wrong with my codes. Thanks.

Some more info about the problem would be useful. Does it even compile? What happens when it runs?

Please use code tags in future, if it's easier to read you may get more responses.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.