Cstrings strSql=_T (" SELECT * FROM qwerasdf ");//table is the key word
_bstr_t bstrSql=strSql;
M_access. GetRecordSet (bstrSql);
FieldsPtr pFields=m_access. M_pRecordset - & gt; The GetFields ();
Int nCount=pFields - & gt; GetCount ();
FieldPtr pField;
Cstrings strTitle strValue;
_variant_t varValue;
////the unknown field name
//for (int I=0; I & lt; NCount; I++)
//{
//pField=pFields - & gt; The GetItem (I);//_com_error
//strTitle. The Format (_T (" % s "), pField - & gt; Name);
//MessageBox (strTitle);
//}
//the known field name
if (! M_access. M_pRecordset - & gt; AdoEOF)
{
Int iValue;
while (! M_access. M_pRecordset - & gt; AdoEOF)
{
VarValue=https://bbs.csdn.net/topics/m_access.m_pRecordset-> GetCollect (_variant_t (0));//_com_error
VarValue=https://bbs.csdn.net/topics/m_access.m_pRecordset-> GetCollect (" ID ");
IValue=https://bbs.csdn.net/topics/varValue.intVal;
StrValue. The Format (_T (" % d "), iValue);
MessageBox (strValue);
//varValue=https://bbs.csdn.net/topics/m_access.m_pRecordset-> GetCollect (_variant_t (1));//_com_error
VarValue=https://bbs.csdn.net/topics/m_access.m_pRecordset-> GetCollect (" value1 ");
StrValue=https://bbs.csdn.net/topics/varValue.bstrVal;
MessageBox (strValue);
//varValue=https://bbs.csdn.net/topics/m_access.m_pRecordset-> GetCollect (_variant_t (2));//_com_error
VarValue=https://bbs.csdn.net/topics/m_access.m_pRecordset-> GetCollect (" value2 ");
StrValue=https://bbs.csdn.net/topics/varValue.bstrVal;
MessageBox (strValue);
M_access. M_pRecordset - & gt; MoveNext ();
}
}
If the code
PField=pFields - & gt; The GetItem (I);
VarValue=https://bbs.csdn.net/topics/m_access.m_pRecordset-> GetCollect (_variant_t (0));//this is the meaning of 0
VarValue=https://bbs.csdn.net/topics/m_access.m_pRecordset-> GetCollect (_variant_t (1));
VarValue=https://bbs.csdn.net/topics/m_access.m_pRecordset-> GetCollect (_variant_t (2));
Why this two sentences are prompt
0 x75e446d2 (located in XXX. Exe) with untreated exception: Microsoft c + + exceptions: _com_error, located in the memory location 0 x00bee87c,
I see a lot of examples were written so ah, I here is not normal
Block out this 2 other normal can query to the data in the database, rule out my database even not wrong data on
the condition of the
Another problem
M_access. M_pRecordset - & gt; GetRecordCount ();//- 1
Why the return value is always 1, traverse the before and after traversal is 1
CodePudding user response:
GetCollect (_variant_t (n)), n is the column indexTry catch catch exceptions
Void PrintComError (_com_error & amp; E)
{
_bstr_t bstrSource (e.S ource ());
_bstr_t bstrDescription (e.D escription ());
//Print COM errors.
Printf (" Error "\ n");
Printf (" \ tCode=% 08 lx \ n ", e.E rror ());
Printf (" \ tCode fancy=% s \ n ", e.E rrorMessage ());
Printf (" \ n \ tSource=% s ", (LPCSTR) bstrSource);
Printf (" \ n \ tDescription=% s ", (LPCSTR) bstrDescription);
}
{
Try
{
.
}
The catch (_com_error & amp; E)
{
PrintComError (e);
}
record number can try SQL SELECT COUNT (*) FROM tablename