I have a stored procedure like this and when I run this stored procedure in SQL Server Management Studio, I only get “Command(s) completed successfully.”</p>
How in my vb.net code with a simple if statement I can check if @onum
is 0 do something.
I never work with this kind, usually stored procedures return an empty row when it doesn't have a value.
ALTER PROCEDURE [dbo].[o_By_RNum]
@rNum varchar(50)
,@ServiceType varchar(50)
,@Direction varchar(1) = NULL
,@VendorID int
AS
Declare @onum int
If @Direction is Null
Begin
SELECT @onum = o_num
FROM RemoteOrder
WHERE r_num LIKE @rNum
AND r_ServiceType = @ServiceType
AND VendorID = @VendorID
End
Else
Begin
SELECT @onum = o_num
FROM RemoteOrder
WHERE r_num LIKE @rNum
AND r_ServiceType = @ServiceType
AND Direction = @Direction
AND VendorID = @VendorID
End
RETURN ISNULL(@onum,0)
and I am calling this stored procedure in my vb.net code like this:
Private Sub DLL_GetOnumFromRemoteOrder_By_RNum(ByRef SqlConn As SqlConnection, ByRef R_NUM As String, ByRef R_SERVICETYPE As String, ByRef DIRECTION As String, ByRef VENDORID As Integer, ByRef RetVal As Integer)
'Open the SQL Connection
If SqlConn.State <> ConnectionState.Open Then SqlConn.Open()
'Add Parameters
Dim command As New SqlCommand("DLL_GetOnumFromRemoteOrder_By_RNum", SqlConn)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add("@rNum", SqlDbType.VarChar).Value = IIf(IsNothing(R_NUM), DBNull.Value, R_NUM)
command.Parameters.Add("@ServiceType", SqlDbType.VarChar).Value = IIf(IsNothing(R_SERVICETYPE), DBNull.Value, R_SERVICETYPE)
command.Parameters.Add("@Direction", SqlDbType.Char).Value = IIf(IsNothing(DIRECTION), DBNull.Value, DIRECTION)
command.Parameters.Add("@VendorID", SqlDbType.Int).Value = IIf(IsNothing(VENDORID), DBNull.Value, VENDORID)
command.Parameters.Add("@RETURN_VALUE", SqlDbType.Int)
command.Parameters("@RETURN_VALUE").Direction = ParameterDirection.ReturnValue
'Dim dr As SqlDataReader
'dr = command.ExecuteReader()
'dr.Read()
'Return dr
'Execute the command
RetVal = command.ExecuteNonQuery()
RetVal = CInt(command.Parameters.Item("@RETURN_VALUE").Value)
End Sub