菜鸟问一个ADO的_RecordsetPtr添加新行问题
我的代码是这样的:
string q="select * from eve_det";
_RecordsetPtr& rs=adoc.GetRecordSet(q.c_str());//adoc.GetRecordSet函数见下文
rs->AddNew();
int scanid=1;
rs->PutCollect("scanid", _variant_t((long)scanid));//每次运行到此就出错,后面就不 写了哈
出错的症状是一个什么内存地址的_com_error错误(我用vs2005调试),然后错误指向msado15.tli(系统自带)文件的Recordset15::PutCollect ( const _variant_t & Index, const _variant_t & pvar )函数。该函数内容就两行
:
HRESULT _hr = put_Collect(Index, pvar);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));//错误指向的地方
这是怎么回事啊。。。
附:
_RecordsetPtr& ADOConn::GetRecordSet(_bstr_t bstrSQL)
{
try
{
//连接数据库,如果Connection对象为空,则重新连接数据库
if (m_pConnection == NULL)
OnInitADOConn();
//创建记录集对象
m_pRecordset.CreateInstance(_uuidof(Recordset));
//取得表中的记录
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error e)
{
cout<<e.Description();
}
//返回记录集
return m_pRecordset;
}
说下意图哈,就是想在结果集里添加几行再update到数据库里去,因为数据量大,所以想用updatebatch,不用insert into,但是这个结果集死活不让我putcollect,为什么啊,请大牛解释阿...
[解决办法]
应该是类型不匹配
rs->PutCollect("scanid", _variant_t((long)scanid));//每次运行到此就出错,后面就不 写了哈
scanid字段如果是整形的话,改成
rs->PutCollect("scanid", long(scanid));