4

The function is

SQLRETURN SQLBindParameter(
      SQLHSTMT        StatementHandle,
      SQLUSMALLINT    ParameterNumber,
      SQLSMALLINT     InputOutputType,
      SQLSMALLINT     ValueType,
      SQLSMALLINT     ParameterType,
      SQLULEN         ColumnSize,
      SQLSMALLINT     DecimalDigits,
      SQLPOINTER      ParameterValuePtr,
      SQLLEN          BufferLength,
      SQLLEN *        StrLen_or_IndPtr);

The documentations I have seen is confusing. Do the arguments depend on the data type or not I found an example here http://support.microsoft.com/kb/248799 which does not seem to work on DB2. I thought odbc was consistent across databases. A specific code example would he helpful.

brian beuning
  • 2,836
  • 18
  • 22
user754425
  • 43
  • 1
  • 3

1 Answers1

10

Its not one line as such but

SQLLEN ival;

ret = SQLBindParameter( stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 100, 0, NULL, 0, &ival );

/*
 * before execution is called
 */

ival = SQL_NULL_DATA;

That inserts a NULL value as a CHAR(100) datatype. Pick the actual datatype to match what your column type is, but the important thing is to set the indicator value to SQL_NULL_DATA before the SQLExecute or SQLExecDirect is called. And make sure its still set to that value at the execute point.

Nick Gorham
  • 1,118
  • 8
  • 9
  • This works. Thanks. Just curuous why do you need to supply the size of the column when the value itself is NULL. – user754425 Jun 27 '11 at 13:22
  • It may or may not need it. In the case of SQL Server for example, the type info in the SQLBindParameter is used to define the type of the parameter, in this case varchar(100), then when the execute is called the value of the parameter is set to NULL. The two bits of info are seperate. What you have to remember is the bound parameter can be reused over many SQLExecute calls, with the ival being changed each time, but the data type stays constant. – Nick Gorham Jun 27 '11 at 14:48