SQLExecDirect in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 12ab09
    New Member
    • Mar 2008
    • 1

    SQLExecDirect in C++

    Hi

    i am using the following code for my development work
    [code=c]
    /* Connect to data source */

    retcode = SQLConnect(hdbc , (SQLCHAR*) "mvr", SQL_NTS,
    (SQLCHAR*) "venk", SQL_NTS,
    (SQLCHAR*) "ram", SQL_NTS);

    if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WIT H_INFO){
    /* Allocate statement handle */
    retcode = SQLAllocHandle( SQL_HANDLE_STMT , hdbc, &hstmt);

    if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WIT H_INFO) {
    /* Process data */
    unsigned char query1[256];
    sprintf((char*) query1,
    "SELECT [col1], [col2], FROM MY_DATA WHERE
    Code:
     = \'%s\' ",
    				pszCode );
    				
                  retcode = SQLExecDirect( hstmt, (SQLCHAR *)query1, SQL_NTS);
    			 				
    //////////////////////////////
    But above code is unable to retrive the data from DB.

    Can you please give me any suggestions.

    where as same query if i run in sql analyzer the values are coming correctly.

    Thanks in advance

    Venkat
    Last edited by sicarie; Mar 22 '08, 01:44 PM. Reason: Code tags
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by 12ab09
    Hi

    i am using the following code for my development work
    [code=c]
    /* Connect to data source */

    retcode = SQLConnect(hdbc , (SQLCHAR*) "mvr", SQL_NTS,
    (SQLCHAR*) "venk", SQL_NTS,
    (SQLCHAR*) "ram", SQL_NTS);

    if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WIT H_INFO){
    /* Allocate statement handle */
    retcode = SQLAllocHandle( SQL_HANDLE_STMT , hdbc, &hstmt);

    if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WIT H_INFO) {
    /* Process data */
    unsigned char query1[256];
    sprintf((char*) query1,
    "SELECT [col1], [col2], FROM MY_DATA WHERE
    Code:
     = \'%s\' ",
    				pszCode );
    				
                  retcode = SQLExecDirect( hstmt, (SQLCHAR *)query1, SQL_NTS);
    			 				
    //////////////////////////////
    But above code is unable to retrive the data from DB.

    Can you please give me any suggestions.

    where as same query if i run in sql analyzer the values are coming correctly.

    Thanks in advance

    Venkat
    My guess is the SELECT query is being interpreted in the C program. Did you try storing it, and then printing it out - make sure all the proper characters are there?

    Comment

    Working...