vc sql 程序运行时提示数据类型varchar转换为int出错 ,已经在分析查询器上验证存储过程正确

bi611 2016-05-18 08:41:39
try
{
if ((FAILED(hr = m_Ado.m_pCommand.CreateInstance(__uuidof(Command)))))//
_com_issue_error(hr) ;
m_Ado.m_pCommand->ActiveConnection = m_Ado.m_pConnection ;//
m_Ado.m_pCommand->CommandType = adCmdStoredProc ;
m_Ado.m_pCommand->CommandText = (LPCTSTR)strCommand ;//


//strtemp.Format("update customer set cname='%s', address='%s',city='%s',province='%s',contact='%s',tel='%s',fax='%s', phone='%s',qq='%s', email='%s', cnote='%s' where cid=%d",
// m_name,m_add, m_city, m_province,m_contact, m_tel, m_fax, m_phone, m_qq, m_mail, m_note,_ttoi(m_id));//

_ParameterPtr pCID;//ID
_ParameterPtr pName;//Ãû
_ParameterPtr pAdd;//add

pCID.CreateInstance(__uuidof(Parameter)) ;
pName.CreateInstance(__uuidof(Parameter)) ;
pAdd.CreateInstance(__uuidof(Parameter)) ;


pName =m_Ado.m_pCommand->CreateParameter("cname",adVarChar,adParamInput,50,(_variant_t)"硒鼓¹");
m_Ado.m_pCommand->Parameters->Append(pName);

pAdd=m_Ado.m_pCommand->CreateParameter("address",adVarChar,adParamInput,50, (_variant_t)"宁波");
m_Ado.m_pCommand->Parameters->Append(pAdd);

int id=10101;
VARIANT vParam;
vParam.vt = VT_INT;
vParam.intVal= id;

pCID =m_Ado.m_pCommand->CreateParameter("cid",adInteger,adParamInput,sizeof(int),vParam);//
m_Ado.m_pCommand->Parameters->Append(pCID);//
m_Ado.m_pRecordset = m_Ado.m_pCommand->Execute(NULL, NULL, adCmdStoredProc) ;
}
catch(_com_error e)
{
AfxMessageBox("error "+e.Description()) ;
}
程序运行时提示:将数据类型varchar转换为int时出错
请问是不是这句出错:
pCID =m_Ado.m_pCommand->CreateParameter("cid",adInteger,adParamInput,sizeof(int),vParam);//
应怎样修改?谢谢!

以上问题已解决,谢谢
原因是参数次序错误。
...全文
97 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-05-19
  • 打赏
  • 举报
回复
坊间传闻,需要先判断是否null

4,012

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧