I have the following sp:
ALTER PROCEDURE [dbo].[ImportLinesProductExists]
@SupplierSKU varchar(50),
@RetVal int output
AS
Select @Retval = count(*) from dbo.ImportLines
Where [SupplierSKUCode] = @SupplierSKU
if @Retval > 0
BEGIN
Return 0
END
And the following code calls the sp:
Public Sub CheckProduct(ByVal _ConnString As String,
ByVal ProductList As List(Of Import_ImportLines.Lines))
Dim ReturnValue As Integer = 0 ' Our Return Value
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
conn.ConnectionString = _ConnString
cmd.Connection = conn
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.CommandText = "dbo.ImportLinesProductExists"
Dim Item As New Import_ImportLines.Lines
For Each Item In ProductList
Dim param As New SqlParameter
param = cmd.Parameters.Add("@RetVal", SqlDbType.Int)
param.Direction = ParameterDirection.ReturnValue
param.Value = 0
param = cmd.Parameters.Add("@SupplierSKU", SqlDbType.VarChar, 50)
param.Value = Item.supplierSKUCode
param.Direction = ParameterDirection.Input
Try
conn.Open()
cmd.ExecuteNonQuery()
ReturnValue = Convert.ToInt32(cmd.Parameters("@RetVal").Value)
Catch ex As SqlException
Throw ex
Finally
conn.Close()
End Try
If ReturnValue = 0 Then
InsertTempProducts(_ConnString, Item)
End If
Next
conn.Close()
End Sub
However all I get when my code is ran, is a execption telling me that my stored proceedure expects the variable @RetVal. I am really lost here, could someone please tell me where I am going wrong.
Kind Regards.
Enter your message below
Sign in or Join us (it's free).