CDatabase CRecordset - How to get the number of rows?
- From: "David++" <David@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Jun 2005 08:19:02 -0700
Hi there,
I'm using Visual C++6 and MFC to connect to a database. So far I have just
been able to connect to the database. I want to count the number of rows in
the database so I can see if there is any data in it. All I want to do is get
the number of rows if possible. I dont need to pass any of the actual data
(if there is any). I've been using the CDatabase class to connect to the
Database and have tried a few things using the CRecordset class to try and
return the number of rows. Here is a cut down version of my code in which I
have removed all the try catch blocks for clarity -
CDatabase db;
db.Open(connectionString);
CRecordset rs(&db);
rs.Open(CRecordset::forwardOnly,_T( "SELECT COUNT (*) FROM Records" ) );
long recordCount = 0;
recordCount = rs.GetRecordCount();
However, when I check the value of recordCount it always returns 1 even when
there are none or many rows in the table.
Any tips on how to do this is much appreciated!
Thanks,
David
.
- Follow-Ups:
- Re: CDatabase CRecordset - How to get the number of rows?
- From: Paul S. Ganney
- Re: CDatabase CRecordset - How to get the number of rows?
- From: Gert
- Re: CDatabase CRecordset - How to get the number of rows?
- From: Bill Thompson
- Re: CDatabase CRecordset - How to get the number of rows?
- Prev by Date: Re: object CWnd
- Next by Date: How to sort CListCtrl on checkbox column?
- Previous by thread: Database Path from DSN (SQL Server)
- Next by thread: Re: CDatabase CRecordset - How to get the number of rows?
- Index(es):
Relevant Pages
|