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



Hi Roy,

This is the code I have so far -

CRecordset rs(&db);

rs.Open(CRecordset::forwardOnly,"SELECT * FROM Records",CRecordset::readOnly);

CDBVariant vtval;
rs.GetFieldValue((short)0,vtval);
int rowcount = vtval.m_lVal;

char buffer[10];
_itoa(rowcount,buffer,10);

FILE *f;
f = fopen("Rows.txt","w");
fprintf(f,"Rows: ");
fprintf(f, buffer);

fclose(f);
rs.Close();

I'm printing the result to a text file for debugging purposes. The database
I'm using was made in Access and the fields are all of type 'Text' so I guess
its returning a char here? That may be the problem

Thanks again,

David

"Roy Fine" wrote:

> David
>
> show some code -- the count function is a single row function - it can not
> return anything but ONE row with one scalar type.
>
> the snip that I provided has no error checking - specifically check the
> datatype of the variant - and if necessary convert it to a long/integer.
>
> roy
>
>
> "David++" <David@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:26D0595F-379A-488D-BD37-9E878CC5D34F@xxxxxxxxxxxxxxxx
> > Ok, I tried this way but now instead of getting 3 rows returned (which is
> how
> > many rows there are in my table), I now get 14549040 rows returned? Hmm,
> any
> > ideas?
> >
> > Thanks,
> >
> > David
> >
> > > Consider something like this (which pushes most of the work to the
> database
> > > server and fetches one row with one field):
> > >
> > > CRecordset rs(&db);
> > > rs.Open(CRecordset::ForwardOnly,"Select count(*) from
> > > Records",CRecordset::ReadOnly);
> > > CDBVariant vtval;
> > > rs.GetFieldValue((short)0,vtval);
> > > int rowcount = vtval.m_lVal;
> > > rs.Close();
> > >
> > >
> > > regards
> > > Roy Fine
> > >
> > >
> > >
>
>
>
.



Relevant Pages

  • Re: CDatabase CRecordset - How to get the number of rows?
    ... I'm now testing my DLL with the real database. ... I know I can connect as the slow algorithm ... David ... "Roy Fine" wrote: ...
    (microsoft.public.vc.mfc)
  • Re: Song
    ... > David wrote: ... >> Roy Schestowitz do you really want to be associated with the Nazis? ... Your problem Dave is that seem to think there is only one ...
    (alt.internet.search-engines)
  • Re: Song
    ... >> David wrote: ... >>> Roy Schestowitz do you really want to be associated with the Nazis? ... Your problem Dave is that seem to think there is only one ...
    (alt.internet.search-engines)
  • Re: Modify Access menu commands when no database running.
    ... David C. Holley wrote: ... At that point, you have the ability to control how the database is named, however the users would still have the ability to change the name *AND* they would still be able to create a new DB directly in Access that bypasses the naming schema. ...
    (microsoft.public.access.modulesdaovba)
  • Re: CDatabase CRecordset - How to get the number of rows?
    ... Best Regards, ... David ... "Roy Fine" wrote: ... > What is the value of dataStr in the CRecordset::Open call. ...
    (microsoft.public.vc.mfc)