Avatar of Zbiebu
Zbiebu
 asked on

Display variable to user

Hi,

How would I display the OUT variable from a Stored Procedure to the user via a MSGBox.
Thanks
Microsoft Development.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Easwaran Paramasivam

8/22/2022 - Mon
SOLUTION
Cluskitt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Zbiebu

ASKER
Hi,
Thanks for your reply.  The Stored Procedure inserts a new data row from the application and the variable returned is the Scope_Identity of the entered row. I would like to display this number to the user.
Thanks
SOLUTION
aplusexpert

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Cluskitt

So, in that case, you have something like:

DECLARE ...
SET ...

INSERT INTO ...

At the very end, you can add:
SELECT @var OutVar

Then, when you're calling the procedure (I use SqlDataAdapter control for these), just fill a DataTable and use the variable from there.
Zbiebu

ASKER
 objCommand.Connection = objConnection
        objConnection.Open()
        objCommand.CommandText = "usp_InsertDetails"
        objCommand.CommandType = CommandType.StoredProcedure

        'Add the parameters for the placeholders in the SQL CommandText Property

        'Parameter for the Title Column
        objCommand.Parameters.AddWithValue("@Title", txtTitle.Text)

        'Parameter for the Description Column
        objCommand.Parameters.AddWithValue("@Description", txtDesc.Text)

        'Parameter for the Section Column
        objCommand.Parameters.AddWithValue("@Section", txtSection.Text)

        'Parameter for the CompiledBy Column
        objCommand.Parameters.AddWithValue("@CompiledBy", txtCompiledBy.Text)

        'Parameter for the Link column
        objCommand.Parameters.AddWithValue("@Link", txtLink.Text)

        'Parameter for the Version column
        objCommand.Parameters.AddWithValue("@Version", txtVersion.Text)

        'Parameter for the Date Column
        objCommand.Parameters.AddWithValue("@Date", DTP1.Text)


        'Execute the SqlCommand object to insert the new data
        Try
            objCommand.ExecuteNonQuery()
        Catch SqlExceptionErr As SqlException
            MessageBox.Show(SqlExceptionErr.Message)
        End Try

        'Close connection
        objConnection.Close()

Open in new window

Hi,
Thanks for that. I use the above code to insert the data. I'm a newbie to this so where within the code above would I place the code that you mention..
Thanks
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.