David++
2005-06-09 15:19:02 UTC
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
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