当前位置: 代码迷 >> DB2 >> SQLBindParameter怎样绑定NULL值,该怎么解决
  详细解决方案

SQLBindParameter怎样绑定NULL值,该怎么解决

热度:10461   发布时间:2013-02-26 00:00:00.0
SQLBindParameter怎样绑定NULL值
对于表中的时间类型,当为空时,直接插入空字符串时会报错提示时间格式不正确,在SQL语句里能插入NULL值,我在C里面用SQLBindParameter该怎样绑定NULL值,写到时间类型的字段里?
SQL="INSERT CTEST (CLT_TIME) VALUES(?)"
parameter="2008-11-06 14:45:33.000000";

  cliRC = SQLBindParameter(hstmt,  
  i,  
  SQL_PARAM_INPUT,  
  SQL_C_CHAR,  
  SQL_CHAR,  
  26,
  0,  
  parameter,  
  0,  
  NULL);  
当时间有值时,是可以插入的,当为空时,就不能插入,提示An invalid datetime format was detected; that is, an invalid string representation or value was specified. SQLSTATE=22007
我该怎么做?
谢谢

------解决方案--------------------------------------------------------
Just Try:
------------------------
cliRC = SQLBindParameter(hstmt,
i,
SQL_PARAM_INPUT,
SQL_C_CHAR,
SQL_CHAR,
26, 
0,
SQL_NULL_DATA, /* use this for test */
0,
NULL);
  相关解决方案