Re: CDatabase CRecordset - How to get the number of rows?
- From: "Bill Thompson" <billt61@xxxxxxxxxx>
- Date: Thu, 9 Jun 2005 15:23:52 -0500
"David++" <David@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4F803144-6DE0-43FF-B232-643B8E52214C@xxxxxxxxxxxxxxxx
> 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
>
>
the GetRecordCount() indicates you have to perform a MoveLast() prior to
getting the record count.
Obviously this is a problem for a forward only recordset. Can't suggest
anything else without knowing more details.
I understand that DAO will become deprecated at some point and that ADO is
the way to go.
.
- References:
- CDatabase CRecordset - How to get the number of rows?
- From: David++
- CDatabase CRecordset - How to get the number of rows?
- Prev by Date: Re: MFC App with Firefox like tabs?
- Next by Date: Re: strtod, _fltin2, and locale changes
- Previous by thread: CDatabase CRecordset - How to get the number of rows?
- Next by thread: Re: CDatabase CRecordset - How to get the number of rows?
- Index(es):
Relevant Pages
|