Getting the number of records in a recordset
-
hi, I have a recordset which contains the results of a query, and I want to get the number of records in the recordset. I tried to use the GetRecordCount function, but I understood that I have to go through the whole recordset in order to get the number of records. So I have this loop in my code which is very inefficient: while (!pSet->IsEOF()) //pSet is a pointer to the recordset pSet->MoveNext(); I thouhgt to do an SQL query using COUNT, but it requires a simple query (something like: SELECT COUNT (*) FROM Table1 ) and my query is not a simple one. It contains selection of a number of records, and Inner joins of tables and an ORDER BY clause. Is there another way to get the number of records in a recordset? Any suggestions?
-
hi, I have a recordset which contains the results of a query, and I want to get the number of records in the recordset. I tried to use the GetRecordCount function, but I understood that I have to go through the whole recordset in order to get the number of records. So I have this loop in my code which is very inefficient: while (!pSet->IsEOF()) //pSet is a pointer to the recordset pSet->MoveNext(); I thouhgt to do an SQL query using COUNT, but it requires a simple query (something like: SELECT COUNT (*) FROM Table1 ) and my query is not a simple one. It contains selection of a number of records, and Inner joins of tables and an ORDER BY clause. Is there another way to get the number of records in a recordset? Any suggestions?
Been a long time since i programmed in ADO but IIRC you don't need to
while (!pSet->IsEOF()) //pSet is a pointer to the recordset
pSet->MoveNext();pSet->MoveLast();
pSet->GetRecordCount();//something like thisHope it helps
The statement below is true.
The statement above is false. -
Been a long time since i programmed in ADO but IIRC you don't need to
while (!pSet->IsEOF()) //pSet is a pointer to the recordset
pSet->MoveNext();pSet->MoveLast();
pSet->GetRecordCount();//something like thisHope it helps
The statement below is true.
The statement above is false. -
U just move to the first record and now loop until the end of records take a variable and increment it inside the loop with MOVENEST() function. the variable holds the total records count
-
Been a long time since i programmed in ADO but IIRC you don't need to
while (!pSet->IsEOF()) //pSet is a pointer to the recordset
pSet->MoveNext();pSet->MoveLast();
pSet->GetRecordCount();//something like thisHope it helps
The statement below is true.
The statement above is false.Monty2 wrote:
pSet->GetRecordCount();//something like this
This will simply give you the “high water mark” — the highest-numbered record yet seen as the user moves through the records.
"The largest fire starts but with the smallest spark." - David Crow
-
hi, I have a recordset which contains the results of a query, and I want to get the number of records in the recordset. I tried to use the GetRecordCount function, but I understood that I have to go through the whole recordset in order to get the number of records. So I have this loop in my code which is very inefficient: while (!pSet->IsEOF()) //pSet is a pointer to the recordset pSet->MoveNext(); I thouhgt to do an SQL query using COUNT, but it requires a simple query (something like: SELECT COUNT (*) FROM Table1 ) and my query is not a simple one. It contains selection of a number of records, and Inner joins of tables and an ORDER BY clause. Is there another way to get the number of records in a recordset? Any suggestions?
SWDevil wrote:
Is there another way to get the number of records in a recordset?
You can use JOINs with the COUNT() clause. Simply put COUNT() around the columns that you are querying.
"The largest fire starts but with the smallest spark." - David Crow
-
Monty2 wrote:
pSet->GetRecordCount();//something like this
This will simply give you the “high water mark” — the highest-numbered record yet seen as the user moves through the records.
"The largest fire starts but with the smallest spark." - David Crow
-
SWDevil wrote:
Is there another way to get the number of records in a recordset?
You can use JOINs with the COUNT() clause. Simply put COUNT() around the columns that you are querying.
"The largest fire starts but with the smallest spark." - David Crow
-
Ok, so just use COUNT(*), leaving the JOIN and WHERE clauses intact.
"The largest fire starts but with the smallest spark." - David Crow
-
Yeah - I know. That's why I need another solution... Is there another way to get the number of records in a recordset other than going through the recordset with a loop or using COUNT? -- modified at 9:23 Tuesday 16th May, 2006
SWDevil wrote:
Is there another way to get the number of records in a recordset other than going through the recordset with a loop or using COUNT?
Have you considered/tried a stored procedure?
"The largest fire starts but with the smallest spark." - David Crow
-
SWDevil wrote:
Is there another way to get the number of records in a recordset other than going through the recordset with a loop or using COUNT?
Have you considered/tried a stored procedure?
"The largest fire starts but with the smallest spark." - David Crow
-
If you are going to be using SQL Server for anything othern than a novelty, I consider it a must-have in the developer's toolbox. http://www.awprofessional.com/articles/article.asp?p=25288&rl=1[^] http://databases.about.com/od/sqlserver/l/aastoredprocs.htm[^] http://www.sqlteam.com/item.asp?ItemID=563[^] http://www.codeproject.com/database/mssqltutorial.asp[^]
"The largest fire starts but with the smallest spark." - David Crow
-
If you are going to be using SQL Server for anything othern than a novelty, I consider it a must-have in the developer's toolbox. http://www.awprofessional.com/articles/article.asp?p=25288&rl=1[^] http://databases.about.com/od/sqlserver/l/aastoredprocs.htm[^] http://www.sqlteam.com/item.asp?ItemID=563[^] http://www.codeproject.com/database/mssqltutorial.asp[^]
"The largest fire starts but with the smallest spark." - David Crow