Sql Output parameter in asp.net 2

I'm trying to create an output parameter from a stored procedure in sql server and then using it inside of my asp.net 2 application.
This is the code I'm using for a function to retrieve the parameter:
-----------------------------------------------------------------------------------------------------
    Public Sub CreateSessionOrdernr()

        Dim dbConn As New SqlConnection(conn)

        Dim sqlString As String = "WebbCreateSessionOrdernr"
        Dim sqlCmd As New SqlCommand(sqlString, dbConn)
        sqlCmd.CommandType = CommandType.StoredProcedure
        Dim myParameter As New SqlParameter
        myParameter.ParameterName = "@maxnr"
        myParameter.SqlDbType = SqlDbType.Int
        myParameter.Direction = ParameterDirection.Output
        sqlCmd.Parameters.Add(myParameter)

        'sqlCmd.Parameters.AddWithValue("@produktID", _produktID)

        dbConn.Open()


        _maxnr = CInt(sqlCmd.Parameters("@maxnr").Value)

        sqlCmd = Nothing
        dbConn.Close()

    End Sub
-----------------------------------------------------------------

And this is the stored procedure:
------------------------------------------------------------------------
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO



alter           PROCEDURE dbo.WebbCreateSessionOrdernr

      (
      @maxnr int OUTPUT
      )

      
AS
      
      Set @maxnr =  (Select MAX(ordernr) From resk_faktura)
      
      
RETURN
-----------------------------------------------------------------

When I execute it it doesn't retrieve any value but is empty.

How can I get it to work?

Peter
peternordbergAsked:
Who is Participating?
 
balochdudeConnect With a Mentor Commented:
try this one..

 dbConn.Open()
sqlCmd.ExecuteNonQuery()
_maxnr = CInt(sqlCmd.Parameters("@maxnr").Value)
0
 
Lee SavidgeCommented:
Hi,

Does the stored procedure return anything if you run it from within Query Analyser/SQL Server Management Studio?

Regards,

Lee
0
 
peternordbergAuthor Commented:
just that it has successfully created the stored procedure

Peter
0
 
peternordbergAuthor Commented:
Of course!

That worked!

Thanks Peter!
0
All Courses

From novice to tech pro — start learning today.