问题
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 srguments 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.
回答1:
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.
来源:https://stackoverflow.com/questions/6486746/looking-for-one-liner-example-how-to-bind-and-insert-a-null-value-into-a-databas