用ado访问access数据库,用下面的语句读取数据
criteria=(_bstr_t)(m_pRecordset->Fields->GetItem(_variant_t("sym0"))->Value);
如果碰上某条记录中该字段是空字符串,则报错。
一个个用try catch过滤太麻烦了!有没有好办法。

解决方案 »

  1.   

    _variant_t TheValue;
    m_pRecordset->Open(bstrSQL,(IDispatch*)m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
    if(!m_pRecordset->adoEOF)
    {
    TheValue = m_pRecordset->GetCollect("lcount");
    if(TheValue.vt!=VT_NULL) //加上这个判断,就可以了 
    {
    int AllCount = TheValue.lVal;
    }

    }
      

  2.   

    CString VariantToCString(_variant_t var)
    {
        CString str;
        if(TheValue.vt!=VT_NULL && TheValue.vt!=VT_EMPTY)
        { 
            str = var.bstrVal;
        }    return str;
    }
      

  3.   

    不是读取数据出错,而是你的强制转换出错,VT_NULL类型的不能转换成字符串,所以你要先把数据取出来,然后判断是字符串类型的话再赋值给字符串