All Forums Database
Vatsala 2 posts Joined 05/07
17 May 2007
Executing SQL Statements through ADO

We execute SQL Statements through ADO in our C++ Applications.In one of the queries, I need to check if there is any data in the table, and if not drop the table and recreate it based on the user's new definition . If data exists, then the application will not do anything.Does anybody know how to do this. In SQL Server, we used to use "IF exists" to do this.

vinod_sugur 22 posts Joined 04/05
17 May 2007

I am not familiar with C++ ADO application i would suggest you to go with following way:Check by executing the select statement SELECT count(*) FROM XYZ;IF the count is zero i your C++ application then drop table and recreate it.Please let me know if this makes sense.

Vatsala 2 posts Joined 05/07
17 May 2007

HiThe problem is that I cannot get the result of this query back into C++. Anybody knows how to get the result of the "Select Count(*)" back into C++ using plain SQL statements. I cannot use Stored procedures etc.

Barry-1604 176 posts Joined 07/05
17 May 2007

The following method is more efficient than doing a count:SELECT 1 WHERE EXISTS (SELECT 1 FROM mytable);If you get a row back, the table contains rows. If not, the table is empty.This method stops when it hits the first row rather than continuing through the table (or index when using an index to count the rows).

vinod_sugur 22 posts Joined 04/05
18 May 2007

I hope the below link will help you:http://www.codeguru.com/cpp/data/mfc_database/ado/article.php/c1141/#more

You must sign in to leave a comment.