SQLBindParameter/SQLExecute returns SQL_NO_DATA on second iteration

Igor Korot 6 Reputation points
2025-01-11T07:13:46.6766667+00:00

Hi, ALL,

I'm trying to run the following scenario:

std::wstring query = L"INSERT INTO abcattbl SELECT ?, ?, (SELECT object_id FROM sys.objects o, sys.schemas s WHERE s.schema_id = o.schema_id AND o.name = ? AND s.name = ?), '', 8, 400, 'N', 0, 0, 34, 0, 'MS Sans Serif', 8, 400, 'N', 0, 0, 34, 0, 'MS Sans Serif', 8, 400, 'N', 0, 0, 34, 0, 'MS Sans Serif', '' WHERE NOT EXISTS(SELECT * FROM dbo.abcattbl WHERE abt_tnam=? AND abt_ownr=?);";

SQLTables( stmt1 );

SQLPrepare( stmt2, query );

for( SQLFetch() )

{

// SQLBindParameter() calls

SQLExecute( stmt2 );

}

Problem is everything runs fine only first time. The second time I'm querting SQL_NO_DATA.

I even tried to add call to SQLFreeStmt( stmt2, SQL_RESET_PARAMS ); but without success.

Could someone explain what needs to be done in order to successfully rebind and re-run the query?

Thank you,

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,276 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,818 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.