Link to home
Start Free TrialLog in
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.
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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Deepu Abraham

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

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.


I should mention that my code will run under window using VC++6 MFC.  My target database are SQL Server and Oracle.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial