locked
@ReturnValue in Legacy Command Object Code RRS feed

  • Question

  • User368742804 posted
    I am troubleshooting some code written in Asp.net 1.1. Below is the code behind a web form:
    Me.cmdSetLastProject = New System.Data.SqlClient.SqlCommand
    ...
            Me.cmdSetLastProject.CommandText = "dbo.[procSetLastProject]"
            Me.cmdSetLastProject.CommandType = System.Data.CommandType.StoredProcedure
            Me.cmdSetLastProject.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
            Me.cmdSetLastProject.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UserLogin", System.Data.SqlDbType.NVarChar, 50))
            Me.cmdSetLastProject.Parameters.Add(New System.Data.SqlClient.SqlParameter("@FirmID", System.Data.SqlDbType.Int, 4))
            Me.cmdSetLastProject.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LastProjectID", System.Data.SqlDbType.Int, 4))
    ...
        Protected WithEvents cmdSetLastProject As System.Data.SqlClient.SqlCommand
    Here's the stored procedure for the command object:
    
    ALTER PROC [dbo].[procSetLastProject]
      @UserLogin nvarchar(50),
      @FirmID int,
      @LastProjectID int
    AS
      UPDATE Users
      SET LastProjectID = @LastProjectID
      WHERE UserLogin = @UserLogin AND FirmID = @FIrmID
    Here's how it is used:
    Private Sub ddlProjects_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlProjects.SelectedIndexChanged
    ' Store selected project for next time
    Dim cnn As SqlConnection = New SqlConnection(strConnection)
    cmdSetLastProject.Connection = cnn
    If Session("UserName") Is Nothing Then GetUserNameFromCookie()
    cmdSetLastProject.Parameters("@UserLogin").Value = Session("UserName")
    If Session("FirmID") Is Nothing Or CInt(Session("FirmID")) = 0 Then Session("FirmID") = GetFirmIDFromCookie()
    cmdSetLastProject.Parameters("@FirmID").Value = CInt(Session("FirmID"))
    cmdSetLastProject.Parameters("@LastProjectID").Value = ddlProjects.SelectedValue
    
    If Me.ddlProjects.SelectedValue <> 0 Then
    'create cookie
    CreateProjectIDCookie(Me.ddlProjects.SelectedValue)
    End If
    
    cnn.Open()
    cmdSetLastProject.ExecuteNonQuery()
    cnn.Close()
    Why is this line in the code behind?
    Me.cmdSetLastProject.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))


    Friday, September 26, 2014 5:17 PM

Answers

  • User-1360095595 posted

    Unless the stored procedure has a "RETURN somevalue" line, there's no need for that line. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 27, 2014 12:55 AM