Quering the SQL Server return SQL_NEED_DATA

Igor Korot 6 Reputation points
2025-01-09T04:03:20.51+00:00

Hi, ALL,

Here is what I have:

  1. I made the following query:
     query2 = L"INSERT INTO abcattbl SELECT ?, 'abcatcol', (SELECT object_id FROM sys.objects o, sys.schemas s WHERE s.schema_id = o.schema_id AND o.name = 'abcatcol' AND s.name = 'dbo'),  \'\', 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='abcatcol' AND abt_ownr='dbo');";
    
  2. The table creation script reads:
     IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='abcattbl' AND xtype='U') CREATE TABLE \"abcattbl\"(abt_os tinyint, abt_tnam nchar(129) NOT NULL, abt_tid integer, abt_ownr nchar(129) NOT NULL, abd_fhgt smallint, abd_fwgt smallint, abd_fitl char(1), abd_funl integer, abd_fstr integer, abd_fchr smallint, abd_fptc smallint, abd_ffce char(18), abh_fhgt smallint, abh_fwgt smallint, abh_fitl char(1), abh_funl integer, abh_fstr integer, abh_fchr smallint, abh_fptc smallint, abh_ffce char(18), abl_fhgt smallint, abl_fwgt smallint, abl_fitl char(1), abl_funl integer, abl_fstr integer, abl_fchr smallint, abl_fptc smallint, abl_ffce char(18), abt_cmnt nchar(254) );
    
  3. The binding code to the first parameter abt_os looks like:
     ret = SQLBindParameter( stmt, 1, SQL_PARAM_INPUT, SQL_C_TINYINT, SQL_TINYINT, 0, 0, &osid, 0, &cbParam[2] );
    
     if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO )
    
     {
    
         GetErrorMessage( errorMsg, STMT_ERROR, stmt );
    
         result = 1;
    
     }
    

This code still returns SQL_NEED_DATA on SQLExecute().

Could someone spot an issue?

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

1 answer

Sort by: Most helpful
  1. LiHongMSFT-4306 29,746 Reputation points
    2025-01-09T06:18:36.7466667+00:00

    Hi @Igor Korot

    SQLBindParameter() succeeds but SQLExecute() returns SQL_NEED_DATA, it usually indicates that you have an incorrect usage of SQLBindParameter(), either the value size or field size.

    Referring from this similar thread: SQLBindParameter and SQLExecute returns SQL_NEED_DATA.

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


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.