out put a variable from store procedure

Posted on 2005-04-23
Last Modified: 2010-04-07

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", =int(varqamonitorid)
        dim returnvalueOPID as string = cmd.parameters("@RETURN_VALUE").value  <-------------------here
        label2.text= "Welcome, " & returnvalueOPID & " !"

create proc dbo.SP_operator_name
@operatorid int,
@operatorname varchar(100) OUTPUT    <----------------output
select @operatorname=operatorname from operator_master where operatorid=@operatorid
Question by:EdwardPeter
    LVL 6

    Accepted Solution

    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


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

    Author Comment


    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

    Author Comment


    I'll repost and hope other experts will join.


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now