VC with ADO Recordset object, get the total number of records of a table!... _ database

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.