Oh, check the information on the Internet, coupled with their own hands-on practice, but also really get the total number of records, in this record key code, later need it!
Remember the first time I get the total number of records when I got a-1, oh, now finally understand what is going on, the original is the choice of cursors Ah!
The key code is as follows
Try//Get the total set of records
{
M_recordset. CreateInstance (_uuidof (Recordset));
M_recordset->open ("SELECT * from Guestbook",
M_connection. Getinterfaceptr (),
adOpenStatic,//with static cursors
adLockOptimistic,
adCmdText
);
int n = m_recordset->getrecordcount ();
CString N;
N.format (the total number of tables guestbook records in the database is:%d, n);
AfxMessageBox (N);
Description: The cursor type of the Recordset object affects whether the number of records can be determined
For forward-only cursors, the RecordCount property returns-1
Returns the actual count for a static or keyset cursor, depending on the data source return-1 or the actual count for the dynamic cursor.
If you open in a static way, the direct GetRecordCount is the number of records, do not need to traverse.
If the cursor is not used incorrectly, GETRECORDCOUNT returns-1.
}
catch (_com_error e)
{
AfxMessageBox ("error!");
AfxMessageBox (E.errormessage ());
AfxMessageBox (E.description ());
return false;
}