Using CDatabase to retrieve the number of records available...

Posted on 2003-12-09
Last Modified: 2013-11-20

I have an application that uses CDatabase and CRecordset.

I connect to the database using  

And send the SQL query using
   CRecordset rs(&db);

Now, I can use...
   for( ; ! rs.IsEOF(); rs.MoveNext() )

To retrieve the data, but is it possible to determine how many records have been generated for the specified query?

GetRecordCount() appears to get only the number of records that have been accessed?

Also, if there are no records to view, I can use CDatabase::ExecuteSQL(...) but assuming the query was an update, how do I find out how many records have been affected???

Thanks for any help,

Question by:jatkin
  • 4
  • 3
  • 2
  • +1
LVL 57

Expert Comment

by:Pete Long
ID: 9902844
Hi gsazeides,
Outlook Is Blocking Attachments

Go to the menu Tools > Options and click on the Security tab then uncheck the box
"Do not allow attachments to be saved or opened that could potentially be a virus"

If that Dosnt Work...

Quit Outlook 2000 if it is running.
Click Start, and then click Run.
In the Open box, type regedit, and then click OK.
Verify that the following key exists. If it does, go to step 5.

If the key path does not exist, create the key path. To create the key path, locate and then select the following registry key:

Click the Edit menu, click New, and then click Key.
Type Office, and then press the ENTER key.
Click the Edit menu, click New, and then click Key.
Type 9.0, and then press the ENTER key.
Click the Edit menu, click New, and then click Key.
Type Outlook, and then press the ENTER key.
Click the Edit menu, click New, and then click Key.
Type Security, and then press the ENTER key.
Click the Edit menu, click New, and then click String Value.
Type the following name for the new value:Level1Remove

Press the ENTER key.
Right-click the new string value name, and then click Modify.
Type the extension of the file type that you want to allow access to from Outlook 2000 as follows:.exe

To specify multiple file types, use the following format:

.exe; .com
When you are finished, click OK.
Exit Registry Editor.
Restart your computer.


Why does it block and what is level1 and level2?

Outlook 2000Sp3, Outlook2002, Outlook2003

This will do it for you in XP

Cannot Open E-Mail Attachments in Outlook Express After You Install SP1:;en-us;q329570

OLEXP: Using Virus Protection Features in Outlook Express 6:;EN-US;291387

*****Blocked files are*****

The 38 file types automatically blocked by Outlook are as follows:

.ade      Microsoft Access project extension
.adp     Microsoft Access project
.bas      Microsoft Visual Basic class module
.bat      Batch file
.chm     Compiled HTML Help file
.cmd     Microsoft Windows NT Command Script
.com     Microsoft MS-DOS program
.cpl       Control Panel extension
.crt       Security certificate
.exe      Program
.hlp       Help file
.hta       HTML program
.inf        Setup  Information
.ins       Internet Naming Service
.isp       Internet Communication settings
.js         JScript file
.jse       Jscript Encoded Script file
.lnk       Shortcut
.mda     Microsoft Access add-in program
.mdb    Microsoft Access program
.mde     Microsoft Access MDE database
.mdz     Microsoft Access wizard program
.msc     Microsoft Common Console Document
.msi      Microsoft Windows Installer package
.msp     Windows Installer patch
.mst      Visual Test source files
.pcd     Photo CD image or Microsoft Visual Test compiled script
.pif       Shortcut to MS-DOS program
.reg      Registration entries
.scr       Screen saver
.sct       Windows Script Component
.shs      Shell Scrap Object
.url       Internet shortcut
.vb       VBScript file
.vbe      VBScript Encoded Script file
.vbs      VBScript file
.wsc     Windows Script Component
.wsf      Windows Script file
.wsh     Windows Script Host Settings file

LVL 57

Expert Comment

by:Pete Long
ID: 9902848
wrong Q sorry

LVL 44

Expert Comment

ID: 9902879
Does this work?

int iNumRecs = rs.GetRecordCount();

Author Comment

ID: 9903149
Tried that, and I still get 1 as a response (the query returns 5)
LVL 23

Expert Comment

by:Roshan Davis
ID: 9903175
What abt this

CRecordset rs(&db);

Rosh :)
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

LVL 44

Assisted Solution

AndyAinscow earned 50 total points
ID: 9903177
Are you getting the recordset after the update query?
If you do loop through
int i = 0;

does i now equal the GetRecordCount() ?

Author Comment

ID: 9903206
Andy,  that is the way I currently do it - and use MoveFirst to get back to the 1st record.
Problem is that with a big query, this can use an excessive amount of time...

Roshmon, interesting idea - I assume by both these responses, the CRecordset/CDatabase does not hold this information so it is not directly available?
LVL 23

Accepted Solution

Roshan Davis earned 50 total points
ID: 9903220


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.

Rosh :)
LVL 44

Expert Comment

ID: 9903242
Roshmons idea with the count function is probably best for you - it should be more efficient than a MoveFirst, MoveNext loop

Author Comment

ID: 9903900
One final thing...

Do you know if it is possible to find out how many rows have been affected using the ExecuteSQL function of CDatabase?
I guess the answer is no, but I thought I'd ask...

Author Comment

ID: 9904642
Never mind...

Created the following function to do it.  I call this before and after the INSERT or DELETE calls to verify (with a reasonable amount of certainty) that the record has been added/deleted...

long CMyClass::GetTotalNoOfRecordsInTable(CDatabase &TheDatabase, CString TableName)
   CRecordset rs(&TheDatabase);
   CString SQLQuery;
   SQLQuery.Format("SELECT COUNT(*) FROM %s;", TableName);
   long RecordCount = atol((CString)rs.Field("COUNT(*)"));
   return RecordCount;

Appears to do what I am after - although I do think Microsoft need a rocket placed somewhere obscure to have functionality such as this missing from the MFC!!!

Thanks again for the help,


Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now