Home › Forums › C Programming › MFC:GetRecordCount()
- This topic has 2 replies, 2 voices, and was last updated 18 years, 10 months ago by sameena.
- AuthorPosts
- February 19, 2006 at 1:36 pm #1933sameenaParticipant
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 - February 20, 2006 at 12:10 pm #3181msaqibParticipant
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
- February 22, 2006 at 8:32 am #3182sameenaParticipant
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
MegaC
- AuthorPosts
- The forum ‘C Programming’ is closed to new topics and replies.