Question : Passing SQL stored procedure output parameter to ASP.net (VB)

I am working with SQL output parameters for the first time, and I'm running into some difficulty.  It's in a stored procedure for an ASP.net (VB) website.

Here is the error message I'm getting at Line 15:

"System.NullReferenceException was unhandled by user code"
Message="Object reference not set to an instance of an object."

If someone is able to review my code and see if they can spot my error, it would be greatly appreciated.




   
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim conSQL As New SqlConnection(strSQLConnection)
        conSQL.Open()

        Dim cmdSQL As New SqlCommand("sp_inventory", conSQL)
        cmdSQL.CommandType = CommandType.StoredProcedure

        Dim paramResult As New SqlParameter
        paramResult.ParameterName = "@TotalUnit1"
        paramResult.Direction = ParameterDirection.Output
        cmdSQL.Parameters.Add(paramResult)


       
        Literal1.Text = cmdSQL.Parameters("@TotalUnit1").Value.ToString


        cmdSQL.ExecuteNonQuery()

        conSQL.Close()
    End Sub
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Alter PROCEDURE [dbo].[sp_inventory]


@TotalUnit1 int OUTPUT

AS

Begin

Select @TotalUnit1 = SUM(Quantity)
From Table1
Where (Condition1 = '1') AND (Condition2 = '2') 
	
END

Answer : Passing SQL stored procedure output parameter to ASP.net (VB)

replace with
1:
2:
3:
4:
5:
Dim paramResult As New SqlParameter
        paramResult.ParameterName = "@TotalUnit1"
paramResult.DbType = DbType.Int32
        paramResult.Direction = ParameterDirection.Output
        cmdSQL.Parameters.Add(paramResult)
Random Solutions  
 
programming4us programming4us