473,388 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Output parameters

I am trying to return an output parameter to my code on executing a
stored procedure. In Query Analyzer, it works with no problem, but when
I run my ASP code below, the output parameter never seems to return
anything. Can anybody help?

Dim cmdNewCampaign, rsNewCampaign, intNumber
Const adCmdStoredProc = &H0004
Const adParamInput = &H0001
Const adParamOutput = &H0002
Const adVarChar = 200
Const adInteger = 3

Set cmdNewCampaign = Server.CreateObject ("ADODB.Command")
cmdNewCampaign.ActiveConnection = strConnection
cmdNewCampaign.CommandText = "AddNewCampaign"
cmdNewCampaign.CommandType = adCmdStoredProc
cmdNewCampaign.Parameters.Append
cmdNewCampaign.CreateParameter("@CampaignName",adV arChar,adParamInput
,100, request("CampaignName"))
cmdNewCampaign.Parameters.Append
cmdNewCampaign.CreateParameter("@CampaignID",adInt eger,adParamOutput)
Set rsNewCampaign = cmdNewCampaign.Execute

intNumber = cmdNewCampaign.Parameters("@CampaignID")


*** Sent via Developersdex http://www.developersdex.com ***
Aug 13 '08 #1
1 2004
Mike P wrote:
I am trying to return an output parameter to my code on executing a
stored procedure. In Query Analyzer, it works with no problem, but
when I run my ASP code below, the output parameter never seems to
return anything. Can anybody help?

Dim cmdNewCampaign, rsNewCampaign, intNumber
Const adCmdStoredProc = &H0004
Const adParamInput = &H0001
Const adParamOutput = &H0002
Const adVarChar = 200
Const adInteger = 3

Set cmdNewCampaign = Server.CreateObject ("ADODB.Command")
cmdNewCampaign.ActiveConnection = strConnection
cmdNewCampaign.CommandText = "AddNewCampaign"
cmdNewCampaign.CommandType = adCmdStoredProc
cmdNewCampaign.Parameters.Append
cmdNewCampaign.CreateParameter("@CampaignName",adV arChar,adParamInput
,100, request("CampaignName"))
cmdNewCampaign.Parameters.Append
cmdNewCampaign.CreateParameter("@CampaignID",adInt eger,adParamOutput)
Set rsNewCampaign = cmdNewCampaign.Execute

intNumber = cmdNewCampaign.Parameters("@CampaignID")

1. SQL Server does not send return or output parameter values until all
resultsets generated by the stored procedure are consumed by the caller. It
appears, by your use of "Set rsNewCampaign = cmdNewCampaign.Execute" that
this procedure is intended to return a resultset. This means that you will
not see your output parameter value until you either close the recordset or
retrieve all the records being returned by the procedure (typically done by
navigating to the last record). I will typically use GetRows to pull all
the records into an array, allowing me to close the recordset and get my
output parameter values, but if you want to avoid using an array, and you
need to use the recordset data after retrieving the output value, you will
need to use a client-side cursor (set the recordset's cursorlocation
property to adUseClient).

2. Those informational "x rows were affected" messages that you see in Query
Analyzer are sent to the caller as resultsets. Those resultsets also need to
be consumed before output and return values are sent. You should make a
practice of suppressing those informational messages by including the line
"SET NOCOUNT ON" in every stored procedure that you write ... unless your
application needs those messages.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Aug 13 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bari Allen | last post by:
I have a Stored procedure in SQL, that works, when tested in SQL, with one input & several output parameters, as follows: CREATE PROCEDURE myProcedure @MyID int , @First varchar(80) OUTPUT ,...
5
by: vivienne.netherwood | last post by:
I am developing an Access Project front end with a SQL server database. I have written a stored procedure that returns a record set and also a value via an output parameter. The procedure is as...
4
by: Janaka | last post by:
Hi this is kind of an ASP.NET/ADO.NET question. I've got a stored procedure on SQL Server that returns a results set. It also sets 3 output parameters in a seperate Select statement. When...
2
by: Bari Allen | last post by:
ASP Classic question: I have a Stored procedure in SQL, that works, when tested in SQL, with one input & several output parameters, as follows: CREATE PROCEDURE myProcedure @MyID int , @First...
3
by: juststarter | last post by:
Hello all, I am executing a stored procedure (on an SQL Server) using ODBC but i can't get the output parameter's value on the client. The stored proc has 3 parameters ,2 of them are input and 1...
1
by: Joe Van Meer | last post by:
Hi all, I have an app that currently runs through 3 seperate stored procedures each returning a count of records. What I would like to do is combine these calls into one call, however I am...
1
by: Garth Wells | last post by:
Using an example in the Jan 2006 release of the Enterprise Library, I came up with the code shown below to create a DAL method for returning several columns of a single row. I place the output...
6
by: c676228 | last post by:
Hi everyone, I wrote a store procedure that fetch one row data in the database based on the parameter value I entered. After I created the store procedure, the store procedure code looks like...
1
by: John Bailo | last post by:
This is a my solution to getting an Output parameter from a SqlDataSource. I have seen a few scant articles but none of them take it all the way to a solution. Hopefully this will help some...
2
by: gabosom | last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure. This is my SP code CREATE PROCEDURE GetKitchenOrderDetail( @idService int, --outPut Variables ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.