Re: CDatabase CRecordset - How to get the number of rows?
- From: "David++" <David@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 10 Jun 2005 06:44:06 -0700
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
> > >
> > >
> > >
>
>
>
.
- Follow-Ups:
- Re: CDatabase CRecordset - How to get the number of rows?
- From: Roy Fine
- Re: CDatabase CRecordset - How to get the number of rows?
- References:
- CDatabase CRecordset - How to get the number of rows?
- From: David++
- Re: CDatabase CRecordset - How to get the number of rows?
- From: Gert
- Re: CDatabase CRecordset - How to get the number of rows?
- From: David++
- Re: CDatabase CRecordset - How to get the number of rows?
- From: Roy Fine
- Re: CDatabase CRecordset - How to get the number of rows?
- From: David++
- Re: CDatabase CRecordset - How to get the number of rows?
- From: Roy Fine
- CDatabase CRecordset - How to get the number of rows?
- Prev by Date: Re: CreateEx used with manifest...
- Next by Date: Re: Reflection not working anymore if creating the child window in a s
- Previous by thread: Re: 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
|