Avatar of AppDevs
AppDevs

asked on 

How do I execute and return one output parameter from a stored procedure which returns two output parameters in ASP.NET?

I have a stored procedure which returns two output parameters.How do I execute and return one output parameter from a stored procedure which returns two output parameters  in ASP.NET?
ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment
Nasir Razzaq
Avatar of jmro20
jmro20
Flag of Puerto Rico image

When you create the parameters there is a property called Direction and set it to Output

After executing evaluate that parameter value.
Avatar of Sara bhai
Sara bhai
Flag of India image

can you show the code both in asp.net and store procedure for simplification?
ASKER CERTIFIED SOLUTION
Avatar of jmro20
jmro20
Flag of Puerto Rico image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of jmro20
jmro20
Flag of Puerto Rico image

There was an error in the loop to add parameters
'Sql Command
mSqlCommand = New SqlCommand
mSqlCommand.Connection = YourConnection
mSqlCommand.CommandTimeout = iTimeout
mSqlCommand.CommandText = yourSP
mSqlCommand.CommandType = CommandType.StoredProcedure

Dim paramArr As SqlParameter() = { _
            New SqlParameter("@ParameterInput", SqlDbType.VarChar, 2), _
            New SqlParameter("@ParameterOutput1", SqlDbType.VarChar, 4), _
            New SqlParameter("@ParameterOutput2", SqlDbType.VarChar)
        }

param(0).Value = yourInputValue
param(1).Direction = ParameterDirection.Output
param(2).Direction = ParameterDirection.Output

'Add Parameters
For Each param As SqlParameter In paramArr
   mSqlCommand.Parameters.Add(param)
 Next

'Exec NonQuery
 mSqlCommand.ExecuteNonQuery()
OutputValue1 = Convert.ToString(mSqlCommand.Parameters"("@ParameterOutput1).Value)
OutputValue2 = Convert.ToString(mSqlCommand.Parameters"("@ParameterOutput2).Value)

Open in new window

SOLUTION
Avatar of Sara bhai
Sara bhai
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of jmro20
jmro20
Flag of Puerto Rico image

That's almost the same I said.
Avatar of jmro20
jmro20
Flag of Puerto Rico image

Correcting another error:
OutputValue1 = Convert.ToString(mSqlCommand.Parameters("@ParameterOutput1").Value)
OutputValue2 = Convert.ToString(mSqlCommand.Parameters("@ParameterOutput2").Value)
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

>How do I execute and return one output parameter from a stored procedure which returns two output parameters  in ASP.NET?

Provide it two parameters but ignore the return value of one parameter.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo