Господа, помогите пожалуйста.
Не могу получить выходной параметр ХП:
create procedure SP_AddRecInTable
@NameRec varchar(200),
@Ident int OUTPUT
as
begin tran AddRecInTable
insert into t_Table(Name)
values (@NameRec)
select Ident =@@identity
commit tran AddRecInTable
Вот Код:
CString strName="TestName";
int RecID;
_CommandPtr pCmd=NULL;
_ParameterPtr pName=NULL,pIdent=NULL;
_variant_t vName,vIdent;
pCmd.CreateInstance(__uuidof(Command));
pCmd->ActiveConnection = Conn;
pCmd->CommandType = adCmdStoredProc;
pCmd->CommandText = _T("SP_AddRecInTable");
vName.vt = VT_BSTR;
vName.bstrVal = _bstr_t((LPCTSTR)strName).copy();
pName = pCmd->CreateParameter(_T("NameRec"),adBSTR,adParamInput,strName.GetLength(),vName);
pIdent = pCmd->CreateParameter(_T("Ident"),adInteger,adParamOutput,sizeof(int),vIdent);
pCmd->Parameters->Append(pName);
pCmd->Parameters->Append(pIdent);
pCmd->Execute(NULL,NULL,adCmdStoredProc|adExecuteNoRecords);
vIdent = pCmd->Parameters->Item[_T("Ident")]->Value;
if (vIdent.vt==VT_I4)
RecID=vIdent.iVal;
Всё вроде работает, только subj никак не могу получить.
(vIdent всегда равен NULL).
В чём может быть дело и как с этим бороться?
(MSSQL2000,MDAC2.6)
ТА>ТА>create procedure SP_AddRecInTable
ТА> @NameRec varchar(200),
ТА> @Ident int OUTPUT
ТА>as
ТА>begin tran AddRecInTable
ТА>insert into t_Table(Name)
ТА> values (@NameRec)
ТА>select Ident =@@identity
ТА>commit tran AddRecInTable
ТА>
хочу заметить, что если передавать один Int, то почему бы не использовать output переменную Result:
return @@identity
ТА>pIdent = pCmd->CreateParameter(_T("Ident"),adInteger,adParamOutput,sizeof(int),vIdent);
попробуй adParamInputOutput (если свойство и называется иначе, то мысль должна быть ясна), в дельфях приходилось устанавливать параметры в положение Input-output для того что-бы все работало.. поможет?
Не надо CreateParameter, AppendParameter и т.п.
а надо Parameters->Refresh();
и далее обращайтесь к параметрам Parameters->GetItem(_T("@Parameter"))->Value
Здравствуйте Трифонов Андрей, Вы писали:
ТА>Господа, помогите пожалуйста.
ТА>Не могу получить выходной параметр ХП:
ТА>ТА>create procedure SP_AddRecInTable
ТА> @NameRec varchar(200),
ТА> @Ident int OUTPUT
ТА>as
ТА>begin tran AddRecInTable
ТА>insert into t_Table(Name)
ТА> values (@NameRec)
ТА>select Ident =@@identity
ТА>commit tran AddRecInTable
ТА>
У тебя прямо так и написано? Или все-таки
select @Ident=@@identity?
Но set @Ident=@@identity все равно правильнее.
Здравствуйте Lexey, Вы писали:
L>У тебя прямо так и написано? Или все-таки
L>select @Ident=@@identity?
L>Но set @Ident=@@identity все равно правильнее.
То и оно, что просто select Ident...
Спасибо всем за помощь.