?
Solved

out put a variable from store procedure

Posted on 2005-04-23
3
Medium Priority
?
293 Views
Last Modified: 2010-04-07
Hi,

Kindly assist what changes needs to be done inorder to return the output from the store procedure called @opeartorname:

        Dim con As New SqlConnection("......")
        Dim cmd As SqlCommand = con.CreateCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "SP_operator_name"
        cmd.Parameters.Add(New SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", DataRowVersion.Current, Nothing))
        cmd.Parameters.Add("@operatorid",SqlDbType.int).Value =int(varqamonitorid)
        con.open()
        cmd.executenonquery()
        dim returnvalueOPID as string = cmd.parameters("@RETURN_VALUE").value  <-------------------here
        label2.text= "Welcome, " & returnvalueOPID & " !"
        cmd.dispose
        cmd.parameters.clear
        con.close





create proc dbo.SP_operator_name
@operatorid int,
@operatorname varchar(100) OUTPUT    <----------------output
as
select @operatorname=operatorname from operator_master where operatorid=@operatorid
GO
0
Comment
Question by:EdwardPeter
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
sansoftura earned 2000 total points
ID: 13851643
Try this

Dim con As New SqlConnection("......")
Dim cmd As SqlCommand = con.CreateCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "SP_operator_name"

Dim inputParam As SqlParameter = cmd.Parameters.Add("@operatorid", SqlDbType.Int)
inputParam.Direction = ParameterDirection.Input
inputParam.Value = int(varqamonitorid)

Dim returnvalueOPID As SqlParameter = cmd.Parameters.Add("@operatorname", SqlDbType.VarChar, 100)
returnvalueOPID.Direction = ParameterDirection.Output

con.Open()
cmd.ExecuteNonQuery()

label2.text= "Welcome, " & returnvalueOPID.Value & " !"
0
 

Author Comment

by:EdwardPeter
ID: 13853409
sansoftura,

Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30452: Operator '&' is not defined for types 'String' and 'System.Data.SqlClient.SqlParameter'.
Source Error:
Line 34:         cmd.executenonquery()
Line 35:         'dim returnvalueOPID as string = cmd.parameters("@RETURN_VALUE").value
Line 36:         label2.text= "Welcome, " & returnvalueOPID & " !"
Line 37:         cmd.dispose
Line 38:         cmd.parameters.clear
Source File: c:\inetpub\wwwroot\cardadd.aspx    Line: 36
0
 

Author Comment

by:EdwardPeter
ID: 13853417
sansoftura,

I'll repost and hope other experts will join.

Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question