Re: CDatabase CRecordset - How to get the number of rows?

Tech-Archive recommends: Fix windows errors by optimizing your registry



"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.


.



Relevant Pages

  • Re: Implementing combo box control linked to table
    ... var Index: Integer; ... RecordCount is not supported in all database types. ... When I tried my associate's program on my Vista machine, ...
    (comp.lang.pascal.delphi.misc)
  • Re: counting records in a recordset
    ... Recordcount will work if you specify the proper type of cursor (the default ... Since this is a SQL database (MS SQL Server, ... after it is entered using an expensive client-side cursor. ...
    (microsoft.public.inetserver.asp.general)
  • Re: counting records in a recordset
    ... Well this is how it works: the data is entered into a database somewhere, ... > client-side cursor, recordcount will work (do you have the ADO ... >>> Please reply to the newsgroup. ...
    (microsoft.public.inetserver.asp.general)
  • CDatabase CRecordset - How to get the number of rows?
    ... I'm using Visual C++6 and MFC to connect to a database. ... 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 ... recordCount = rs.GetRecordCount; ...
    (microsoft.public.vc.mfc)
  • Re: add data from a datagrid
    ... what can I do, I use on a form a datagrid, and a commandbutton. ... .CursorLocation = adUseServer ... Otherwise the RecordCount property may not be correct. ... This would let the database server count up the records, ...
    (microsoft.public.vb.general.discussion)