如何使用ADO和C++; 技术:微软SQL Server 2008、ADO、C++、
代码: 当pComand->Execute时,我得到异常:如何使用ADO和C++; 技术:微软SQL Server 2008、ADO、C++、,c++,sql-server,stored-procedures,ado,C++,Sql Server,Stored Procedures,Ado,代码: 当pComand->Execute时,我得到异常: Code: 80040e10 (IDispatch error #3088) Source: Microsoft OLE DB Provider for SQL Server Desc: "Procedure 'MyProc' expects parameter '@ID', which was not supplied." 将最后一个参数添加到CreateParameter后: ADODB::_ParameterPtr pParam
Code: 80040e10 (IDispatch error #3088)
Source: Microsoft OLE DB Provider for SQL Server
Desc: "Procedure 'MyProc' expects parameter '@ID', which was not supplied."
将最后一个参数添加到CreateParameter后:
ADODB::_ParameterPtr pParam_ID = pCommand->CreateParameter("ID",
ADODB::adInteger, ADODB::adParamInput, sizeof(long), _variant_t(0));
存储过程执行时没有错误,但@ID不为null
从
在C/C++中,必须指定所有操作数。如果要指定数据类型为字符串的缺少参数,请指定包含空字符串的_bstr_t。如果要指定数据类型为Variant的缺失参数,请指定值为DISP_E_PARAMNOTFOUND且类型为VT_ERROR的_Variant。或者,指定由#import指令提供的等效_variantt常量vtmission
有什么想法吗?解决了:
_variant_t v_ID;
v_ID.vt = VT_NULL; // by default vt is VT_EMPTY
// by default if last parameter not provided
// it equals vtMissing (it isn't VT_NULL equivalent)
ADODB::_ParameterPtr pParam_ID = pCommand->CreateParameter("ID",
ADODB::adInteger, ADODB::adParamInput, sizeof(long), v_ID);
_variant_t v_ID;
v_ID.vt = VT_NULL; // by default vt is VT_EMPTY
// by default if last parameter not provided
// it equals vtMissing (it isn't VT_NULL equivalent)
ADODB::_ParameterPtr pParam_ID = pCommand->CreateParameter("ID",
ADODB::adInteger, ADODB::adParamInput, sizeof(long), v_ID);