Results 1 to 2 of 2
  1. #1
    Join Date
    May 2007
    Posts
    1

    Question Unanswered: Yet another SQLBindParameter thread -- char* as a parameter? (already did a search)

    Hi guys, first post here. It's been a few years since I've worked with ODBC, so I'm a bit rusty. I'm having trouble figuring out how to use a char* string as a parameter for a SELECT statement. I'm trying to compare the contents of a varchar column (with size=20) against the string.

    Here's the code that I'm using:


    Code:
    char* arg;
    SQLINTEGER stringSize = 32;
    
    retcode = SQLBindParameter(hstmt, 
                               1, 
                               SQL_PARAM_INPUT, 
                               SQL_C_CHAR, 
                               SQL_VARCHAR, 
                               20,
                               0,
                               arg, 
                               stringSize, 
                               &stringSize);
    
    retcode = SQLPrepare(hstmt, 
                         (SQLCHAR*) "SELECT * "
                                    "FROM   myTable "
                                    "WHERE  (stringColumn = '?')",
                         SQL_NTS);
    
    retcode = SQLExecute(hstmt);
    
    retcode = SQLFetch(hstmt);
    When SQLFetch() runs, it returns 100 (SQL_NO_DATA). If I type the query manually into my Enterprise Manager console, I get several results, so I know the query is correct. Any idea what I might be doing wrong with the ODBC calls?

    Thanks!

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    the code example here (scroll to bottom) has an example of calling SQLBindParameter with SQL_C_CHAR.

    http://msdn2.microsoft.com/en-us/library/ms710963.aspx

    EDIT: from my reading of the example, I think you may want to do this: (stringColumn = ?) and not this (stringColumn = '?') in your call to SQLPrepare.
    Last edited by jezemine; 05-03-07 at 19:21.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •