Home Forums C Programming MFC:GetRecordCount()

Viewing 2 reply threads
  • Author
    • #1933

      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


      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!


    • #3182

      Hi Yes I thought it would be a great function like Clippers various functions but it does not work.

      From http://www.codeproject.com/ 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 help

      • This reply was modified 8 years, 12 months ago by M. Saqib.
      • This reply was modified 1 year, 3 months ago by M. Saqib.
Viewing 2 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.