Avatar of bsuttiratana
bsuttiratana

asked on 

Get the record count by C++ and OLEDB.

Can someone give me the sample of code in C++ that show me how to get the record count of the table in database by using oledb commands?

Thanks.
C++

Avatar of undefined
Last Comment
AlexNek
Avatar of AlexNek
AlexNek

Run SQL command  like this one
select count(*) as records_Number from <table Name>  [Where ....]
ASKER CERTIFIED SOLUTION
Avatar of bijopuli
bijopuli
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Deepu Abraham
Deepu Abraham
Flag of United States of America image


CString strCommand;
strCommand.Format(_T("SELECT COUNT(*) FROM '%s';"), szTableName);
Then EecuteQuery() should retrive the count of the records of a prticualr table.

Best Regards,
DeepuAbrahamK
Avatar of bsuttiratana
bsuttiratana

ASKER


What I have in mind is I will have a method which will have the sql statement as input and return the number of records.

szSqlStr should be the sql statement like "select count(*) from MyTable".  MyTable will be any table depends on the caller.

LONG ExecCountSql(LPCSTR szSqlStr );
{

}


Bijo.

How can I construct the command "pICommandText" from the sql statement and how can I get the record count from your code?

The tables might be very large.  I am concern abount the performance.  Do you think your code will  impact the performance?  What I need is just the record count.  Nothing else.

Avatar of bsuttiratana
bsuttiratana

ASKER


I should mention that my code will run under window using VC++6 MFC.  My target database are SQL Server and Oracle.
SOLUTION
Avatar of AlexNek
AlexNek

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo