Link to home
Start Free TrialLog in
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
SOLUTION
Avatar of Cluskitt
Cluskitt
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zbiebu
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of 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
ASKER CERTIFIED SOLUTION
Avatar of Easwaran Paramasivam
Easwaran Paramasivam
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial