Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / March 2006

Tip: Looking for answers? Try searching our database.

Retrieving OUTPUT parameter from Stored Procedure

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BFSmith - 04 Mar 2006 15:13 GMT
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.Y.M. Wong-A-Ton - 04 Mar 2006 15:50 GMT
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.
---
S.Y.M. Wong-A-Ton

> 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:
[quoted text clipped - 33 lines]
> and I get : Cannot use the OUTPUT option when passing a constant to a stored
> procedure
BFSmith - 04 Mar 2006 17:41 GMT
wow...that's a mouthfull...any chance you have a js example of such a beast?

> 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.
[quoted text clipped - 49 lines]
> > and I get : Cannot use the OUTPUT option when passing a constant to a stored
> > procedure
S.Y.M. Wong-A-Ton - 05 Mar 2006 15:55 GMT
var conn = new ActiveXObject("ADODB.Connection");
conn.ConnectionString = "driver={sql
server};server=(local);database=YourDBName;uid=sa;pwd=;";
conn.Open();

var cmd = new ActiveXObject("ADODB.Command");
cmd.ActiveConnection = conn;
cmd.CommandText = "your_stored_proc_name";
cmd.CommandType = 0x0004;  // adCmdStoredProc

var param = new ActiveXObject("ADODB.Parameter");
param.Name = "@output_parameter";
param.Direction = 0x0002;  // adParamOutput
param.Type = 3; // adInteger
cmd.Parameters.Append(param);

var param2 = new ActiveXObject("ADODB.Parameter");
param2.Name = "@input_parameter";
param2.Direction = 0x0001; // adParamInput
param2.Type = 200; // adVarChar
param2.Size = 10;
param2.Value = "testing123";
cmd.Parameters.Append(param2);

var parameters;
var recs;
cmd.Execute(recs, parameters);

conn.Close();

cmd.Parameters.Refresh;

XDocument.UI.Alert(cmd.Parameters[0].Value);  // Retrieve output param value

----
For a sample ODBC connection string corresponding to your database type look
on
http://www.connectionstrings.com

Look on http://www.winscripter.com/ASP/Database/46.aspx to find the correct
ADO constants (such as adChar or adVarChar, etc.) in JScript for the data
types used in your stored procedure.

You might experience ADO security issues when running this code. Perhaps you
should look into using web services
(http://msdn.microsoft.com/library/en-us/odc_ip2003_ta/html/OfficeInfoPathWebServ
iceASPNET.asp?frame=true
) if this does not work for you.
---
S.Y.M. Wong-A-Ton

> wow...that's a mouthfull...any chance you have a js example of such a beast?
>
[quoted text clipped - 51 lines]
> > > and I get : Cannot use the OUTPUT option when passing a constant to a stored
> > > procedure
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.