Hello all,
I have a vb.net code which executes the stored procedure talking one parameter if the parameter value already exists then return -1 else insert the record in the table and return 0
But after the application is run and if the new value comes then it insert into the table but returns 1 instead of 0. When I execute the procedure in SQL it retruns 0.
Can anyone tell me why am I getting the wrong return value.
VB.NET code:
Private Function GetDataSet() As DataSet
Dim prodstr As String
Dim returnval As Integer
Try
prodstr = Me.ListBox2.SelectedValue
Dim cmd As New SqlCommand("zcheckprod " & "'" & prodstr & "'", cn)
If cn.State = ConnectionState.Closed Then
cn.Open()
End If
returnval = cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
MessageBox.Show(returnval)
End Function
--
The SQL stored procedure:
CREATE PROC zcheckadmin
@prod char(5)
as
Declare @i as int
Select @i = count(*) from table1 where
comproduct=@prod
If Isnull(@i,0) = 0
Begin
Insert Into table1 (comproduct,measure)
Select @prod, 0
return 0
End
ELSE
print 'exists'
return -1
Thanks,
-V
I have a vb.net code which executes the stored procedure talking one parameter if the parameter value already exists then return -1 else insert the record in the table and return 0
But after the application is run and if the new value comes then it insert into the table but returns 1 instead of 0. When I execute the procedure in SQL it retruns 0.
Can anyone tell me why am I getting the wrong return value.
VB.NET code:
Private Function GetDataSet() As DataSet
Dim prodstr As String
Dim returnval As Integer
Try
prodstr = Me.ListBox2.SelectedValue
Dim cmd As New SqlCommand("zcheckprod " & "'" & prodstr & "'", cn)
If cn.State = ConnectionState.Closed Then
cn.Open()
End If
returnval = cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
MessageBox.Show(returnval)
End Function
--
The SQL stored procedure:
CREATE PROC zcheckadmin
@prod char(5)
as
Declare @i as int
Select @i = count(*) from table1 where
comproduct=@prod
If Isnull(@i,0) = 0
Begin
Insert Into table1 (comproduct,measure)
Select @prod, 0
return 0
End
ELSE
print 'exists'
return -1
Thanks,
-V