Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 8th, 2008, 07:22 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Default [Resolved] Get return value from stored procedure

I am having difficulties getting a result back after calling a sp. Most likely this is due to me not understanding the interaction. Wonder if someone could help?

Here is my VB 2005 code:

Code:
EquentialCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@RetValue", Data.SqlDbType.Char, 50))
EquentialCommand.Parameters("@RetValue").Direction = Data.ParameterDirection.Output
EquentialCommand.CommandType = Data.CommandType.StoredProcedure
EquentialCommand.CommandText = ("sp_Vecellio_JobInquiry1")
EquentialCommand.Connection = EquentialConnection
mySqlDataAdapter.SelectCommand = EquentialCommand
RetValue = EquentialCommand.Parameters("@RetValue").Value.ToString
If RetValue <> Nothing Then
                myError = True
                ASPNET_MsgBox(RetValue)
            Else
                mySqlDataAdapter.Fill(mySqlDataTable)
                EquentialCommand.Parameters.Clear()
                EquentialConnection.Close()
End If
Her is my query snippet:

Code:
CREATE PROCEDURE dbo.sp_Vecellio_JobInquiry1
(
    @JobNumber INT,
    @UserID VARCHAR(10),
    @Text VARCHAR(20) = NULL,
    @DateFrom DATETIME = NULL,
    @DateTo DATETIME = NULL,
        @RetValue CHAR(50) OUTPUT
)

AS

SET NOCOUNT ON

CREATE TABLE    #AuthorityTable
        (
            busunit_from BIGINT,
            busunit_to BIGINT
        )

INSERT    #AuthorityTable
    (
        busunit_from,
        busunit_to
    )

SELECT    msmcuf, msmcut
FROM    OPENQUERY(vgsys400, 'SELECT * FROM vgisec.f0001')
WHERE    msuser = @UserID

IF @@ROWCOUNT = 0
    BEGIN
    SET @RetValue = 'You are not authorized to any selections.'
    RETURN
    END


If I do not find any records from the 'openquery' then I would like to return message to my program
 
Old August 8th, 2008, 11:05 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Finally solved my vb code this way:

Code:
EquentialCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@RetValue", Data.SqlDbType.Char, 50)).Value = Nothing
            EquentialCommand.Parameters("@RetValue").Direction = Data.ParameterDirection.Output
            EquentialCommand.CommandType = Data.CommandType.StoredProcedure
            EquentialCommand.CommandText = ("sp_Vecellio_JobInquiry1")
            EquentialCommand.Connection = EquentialConnection
            mySqlDataAdapter.SelectCommand = EquentialCommand
            mySqlDataAdapter.Fill(mySqlDataTable)
            Dim ReturnValue As String = EquentialCommand.Parameters("@RetValue").Value.ToString
            If ReturnValue <> Nothing Then
                myError = True
                ASPNET_MsgBox(ReturnValue)
            Else
                EquentialCommand.Parameters.Clear()
                EquentialConnection.Close()
            End If
        Catch ex As Exception
            ErrorString = ex.ToString
            ASPNET_MsgBox("An error has occurred connection to server and loading table: " + vbCrLf + ErrorString)
        End Try







Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure return value is NULL kshort ASP.NET 2.0 Basics 16 March 14th, 2017 12:45 PM
Stored Procedure return value dmiles C# 3 December 6th, 2007 05:20 AM
how can i return a recrdset in a stored procedure? arathy ASP.NET 1.0 and 1.1 Basics 0 December 12th, 2006 04:24 AM
Can i return a recordset in a Stored procedure chiefouko VB Databases Basics 6 December 12th, 2006 03:34 AM
how i use the Stored Procedure return value and ho yoord ADO.NET 5 June 28th, 2004 08:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.