当前位置:首页 > 在对应所需名称或序数的集合中 未找到项目

在对应所需名称或序数的集合中 未找到项目

点击次数:3841  更新日期:2014-11-03

从数据库中读取第一个字段的时候,下面这样写,会提示“在对应所需名称或序数的集合中 未找到项目”

Fields* fields = NULL;

this->m_pRecordset->get_Fields(&fields);

try{

    if(!this->m_pRecordset->adoEOF){

        CString r=(_bstr_t)fields->Item[0]->GetValue();

        return r;

    }

catch(_com_error& e)

{

}

解决方法是

Item[]这里传入long类型,即

CString r=(_bstr_t)fields->Item[(long)0]->GetValue();