Retrieving OUTPUT parameter from Stored Procedure

B

BFSmith

I have a sp that has one input parameter (Piece char(7)) and one output
parameter (Cost )...the sp works fine but I can't figure out how to:
a) get the sp to run in ip
b) I really need the OUTPUT parameter

sp: PROCEDURE dbo.prGetPieceReprocCost (
@Piece char(7),
@Cost smallmoney = null output
)

Both Piece & Cost are in the main data source.

My code so far is:
function btnReproc::OnClick(eventObj)
{
//Retrieve the value of the field that you want to use as a parameter
//to the stored procedure.
var sPiece =
getNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/d:tblRADetail/@Piece");
XDocument.UI.Alert(sPiece);

//Set the Command for the Query Adapter of the Data Source. Incorporate the
//parameter values that you want to use.
var retCost = 0
var strSQL = 'execute "prGetPieceReprocCost" ' + '"' + sPiece + '"' + '
,retCost output';
XDocument.UI.Alert(strSQL);

XDocument.QueryAdapter.Command = strSQL;

//Query the Data Source.
XDocument.Query();


The strSQL is : execute "prGetPieceReprocCost" "447359M" ,retCost output

and I get : Cannot use the OUTPUT option when passing a constant to a stored
procedure
 
S

S.Y.M. Wong-A-Ton

The Command property of the QueryAdapter is a string, not an object, which is
why you are getting the error, since the OUTPUT parameter cannot be returned.
You will not be able to retrieve an output value returned by a stored
procedure by using this Command property. You need to use the Command object
of ADODB (see http://support.microsoft.com/?kbid=185125).

For JScript, you would have to instantiate a Command object like this:
var objCommand = new ActiveXObject("ADODB.Command");

Then set the ActiveConnection and fill the Parameters collection on the
Command object, call Execute on the Command object, close the connection,
refresh the Parameters collection, and then retrieve the value of the output
parameter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top