Click to See Complete Forum and Search --> : How to use output param in a stored procedure thru. vc++


Md Noorul
October 29th, 1999, 11:16 PM
Hi,

I am working in vc++(MFC) connected to sybase adaptive server anywhere(ODBC).
I am having trouble getting results from a stored Procedures.

The object is to execute a stored procedure and get the result.
I tried using output parameters,but it's not yielding.
(I am able to pass parameters to a stored procedure)

Help me to solve this problem.

rds,
Md.Noorul

Cih
November 2nd, 1999, 02:11 AM
Hi!

I had similar problem in OLE DB. I had to use following syntax:

"? = call ProcedureName (?, ?,...)"

to get return value and output parameters back.

Regards
Cih

Md Noorul
November 2nd, 1999, 10:45 PM
Hello,

Thank you for your reply.

But I had tried this syntax.
It is working only for input parameters.

For output parameters I am using like this...
///////////////////////////////////////////////////////////////////////////////////////////////
////////////In DoFieldExchange
pFX->SetFieldType(CFieldExchange::outputParam);
RFX_Text(pFX, _T("[count]"), m_outParam);

///////In Open function
Open(0,"{Call GetCount(?)}");

/////////////////////Stored procedure in backend
alter procedure mmd.GetCount(out @cnt varchar(10))
/* RESULT ( column-name,... ) */
begin
select COUNT(*) into @cnt from mmd.PatientInfo;
select* from mmd.Social_Info,mmd.PatientInfo where Social_Info.PatientId='3'
end
///////////////////////////////////////////////////////////////////////////////////////////////
But this is not working.
pl.check this and inform me if you find any error.
Or get me a way to solve this problem in other way.

Regards,
Md.Noorul

Andrew Luit
November 3rd, 1999, 08:28 PM
Here I is some code, wish it will help you.

global variables:
_ConnectionPtr pConn;
_CommandPtr pCommand;

code for connection:
HRESULT rslt;
CoInitialize(NULL);
rslt=pConn.CreateInstance("ADODB.Connection");
rslt=pConn->Open("DSN=?","<User name>","passward",adOpenUnspecified);
hr=pCommand.CreateInstance("ADODB.Command");


code in get parameter:

_ParameterPtr pParaIn;
_ParameterPtr pParaOut;
ParametersPtr pParas;
BSTR bstrValue;
<assign the input parameter to bstrValue>
pParaIn=pCommand->CreateParameter("<Index string>",adBSTR,adParamInput,sizeof(bstrValue),bstrValue);
pParas=pCommand->Parameters;
pParas->Append(pParaIn);
pParas->Append(pParaOut);
pCommand->ActivConnection=pConn;
pCommand->CommandType=adCmdStoredProc;
pCommand->CommandText="Procedure Name";
pCommand->Execute(?,?,adCmdStoredProc);
Now, the out put parameter may in pParaOut.