Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003
    Posts
    17

    Unhappy Unanswered: how to insert a null-value using SQLBindParameter

    hi,

    i got difficulties inserting a NULL-value into my table:
    to tell ODBC, that i want to insert a NULL-value, i use a variable (SQLINTEGER) with a value of SQL_NULL_DATA as last argument to SQLBindParameter:

    buffer = new char[255];
    strcpy(buffer,"");
    SQLINTEGER nInd = SQL_NO_DATA;
    SQLPrepare(myHandle,"INSERT INTO TEST (col1) VALUES(?)",SQL_NTS);
    SQLBindParameter(myHandle,firstcolumn, SQL_PARAM_INPUT, SQL_C_CHAR,SQL_VARCHAR, 0,0, (void*)buffer, 0, &nInd);
    SQLExecute(myHandle);

    when i call execute a get an access violation

    any idea ?

  2. #2
    Join Date
    Jan 2003
    Posts
    17

    Cool Re: how to insert a null-value using SQLBindParameter

    solution:
    1. the length values have to be at least 1 (don't ask me why) otherwise you get an adequate error message.
    2. nInd has to be a pointer to SQLINTEGER at least SQLINTEGER[8];

    why ? i don't know.

    SQLINTEGER nInd[8];
    *(SQLINTEGER*)nInd = SQL_NULL_DATA;
    SQLBindParameter(myHandle,firstcolumn, SQL_PARAM_INPUT, SQL_C_CHAR,SQL_VARCHAR, 1,0, (void*)buffer, 1, nInd);

    i red at least 20 documentations about SQLBindParameter and didn't find a solution. try and error led to the solution - thanks to Bill - the documentations of microsoft give more confusion than help.

Posting Permissions

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