MFC:GetRecordCount()

Home Forums C Programming MFC:GetRecordCount()

This topic contains 2 replies, has 2 voices, and was last updated by  sameena 11 years, 9 months ago.

  • Author
    Posts
  • #1933

    sameena
    Member

    Hi
    The GetRecordCount() function seems really great but it does not work correctly. I have read that this is the way it is. One would assume that once you set a filter and then close and reopen the database with the same filter it would apply but it does not you have to issue commands to travel through the database so that one might as well as override this function with your own code that loops through the entire dataset counting the records that meet your criteria.Has anyone perhaps solved this getrecordcount() problem?
    Thanks MegaC

  • #3181

    msaqib
    Participant

    Hello,

    Sureyly GetRecordc**t is a great function. I am not an experienced C++ user but that problem is with many of the database programmers working in different languages. I got this problem while working on an ASP project.  So coming to your point. The GetRecordc**t is supported by both Access and SQL Server. I can’t speak for sure on other platforms, but I’ve been told it’s a pretty widely supported feature and I’d assume most vendors have some way of doing it.
    So why isn’t it working for you? Well it’s supported only if the recordset supports approximate positioning (adApproxPosition) or bookmarks (adBookmark).
    And here is another solution to that. If you only need the records count you can use SELECT COUNT(field_name) FROM table_name; and use where clause in it fr more refinement. With some thought and a little bit of trial and error, you’ll soon be counting anything you want in the database!

    Thanks
     

  • #3182

    sameena
    Member

    HiYes I thought it would be a great function like Clippers various functions but it does not work. From http://www.codeproject.com/scrapbookcrecordsetnonos.asp” Caution The record count is maintained as a “high water mark” “the highest-numbered record yet seen as the user moves through the records. The total number of records is only known after the user has moved beyond the last record. For performance reasons, the count is not
    updated when you call MoveLast. To count the records yourself, call MoveNext repeatedly until IsEOF returns nonzero. Adding a record via CRecordset:AddNew and Update increases the count; deleting a record via CRecordset::Delete decreases the count.”You open the databae set a filter and cannot query the database using GetRecordCount(). You have to move beyond the last record for some reason.
    Thanks for your helpMegaC

You must be logged in to reply to this topic.

0 Shares
Share
+1
Tweet
Share
Stumble