Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ODBC in C++: Need row count on SELECT query

Posted on 2007-11-21
3
Medium Priority
?
2,685 Views
Last Modified: 2008-02-01
When you prepare and execute a SQL statement, but before you fetch the results, is there any way to know how many rows there are in the result set?  I need to create an array with the same number of elements.

Here's the application flow:
Execute SQL statement.
Bind columns to vars.
                         <-- I need the row count here so I can make an array of n elements.
Fetch rows.

The ODBC API has a function called SQLRowCount(), but MSDN says it only returns the number of rows affected by insert, update, or delete queries.  It mentions nothing about select queries.  I know I can read the entire result set to get the count, reset the cursor, and then read it again, but that is just inefficient.

Any ideas?
0
Comment
Question by:cuziyq
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
SQL_SERVER_DBA earned 750 total points
ID: 20328624
select count(*) from table
0
 
LVL 14

Author Comment

by:cuziyq
ID: 20328758
DUH!  I am such an idiot!  Maybe I should think before I post next time ;-)
0
 
LVL 30

Expert Comment

by:Axter
ID: 20328904
>>I need to create an array with the same number of elements.

I recommend using a vector container, so that you don't need to know the number of elements needed for the array.

A std::vector container will grow to the size you need it, as you add elements to it.

It's also a safer approach over using new or malloc, since the vector will automatically clean up the memory.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question