Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 2003-12-09
Medium Priority
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:James Atkin
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:

OLEXP: Using Virus Protection Features in Outlook Express 6:

*****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 45

Expert Comment

ID: 9902879
Does this work?

int iNumRecs = rs.GetRecordCount();
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

by:James Atkin
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 :)
LVL 45

Assisted Solution

AndyAinscow earned 150 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

by:James Atkin
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 150 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 45

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

by:James Atkin
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

by:James Atkin
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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