VC++ 通过ADO连接数据库查询时返回空值报错的解决方案
时间:2022-03-10 17:39
当数据库的字段值允许为空时, 而且此时内容也为空时,则执行查询会出错,例如
CString str = pRecordset->GetFields()->GetItem((long)0)->GetValue();
或者
str= pRecordset->GetCollect("posInfo");
会弹出如下窗口提示出错!
更加奇怪的是 catch(...)也抓不到异常
_variant_t var; var= m_pRecordset->GetCollect("posInfo"); //可能为空 if(var.vt != VT_NULL) //为NULL { strPosInfo = var; } else { strPosInfo = “”; }
就可以检测NULL值了
VC++ 通过ADO连接数据库查询时返回空值报错的解决方案,布布扣,bubuko.com