Home All Groups Group Topic Archive Search About

Unable to recognize stored procedure param

Author
2 Mar 2006 4:37 PM
Virgil
Hello,

I am attempting to create a small app that executes a stored procedure
in SQLServer and have been unsuccessful in getting the procedure to
execute from my application.  The error received when issuing the
ExecuteNonQuery is "Procedure 'TestProc' expects parameter '@IN', which
was not supplied.".

Any help would be greatly appreciated. Below is a test stored proc and
code.

Thanks,
Virgil

----------------------------------------------------------------------------------------------

create procedure TestProc
(@IN int
,@OUT int OUTPUT
)
as

set @OUT = 10


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim ConnString As String = "**************"  '<-- not displayed
        Dim Connection As SqlConnection
        Dim Command As SqlCommand
        Dim InParam As SqlParameter
        Dim OutParam As SqlParameter

        Try

            ' Create connection
            Connection = New SqlConnection(ConnString)
            Connection.Open()

            ' Create Command
            Command = New SqlCommand("TestProc", Connection)
            Command.CommandType = CommandType.StoredProcedure

            '  Create parameters
            InParam = New SqlParameter("@IN", SqlDbType.Int)
            InParam.Direction = ParameterDirection.Input
            'Command.Parameters.AddWithValue("@IN", 1)

            OutParam = New SqlParameter("@OUT", SqlDbType.Int)
            OutParam.Direction = ParameterDirection.Output

            ' Add the parameters to the command
            Command.Parameters.Add(InParam)
            Command.Parameters.Add(OutParam)

            ' Execute the command
            Command.ExecuteNonQuery()

            ' Show results
            MessageBox.Show(Command.Parameters(1).Value)

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        Finally
            If (Connection Is Nothing) = False Then
                If Connection.State = ConnectionState.Open Then
                    Connection.Close()
                End If
            End If
        End Try

    End Sub

Author
2 Mar 2006 7:30 PM
Jim Wooley
Show quote Hide quote
> Hello,
>
> I am attempting to create a small app that executes a stored procedure
> in SQLServer and have been unsuccessful in getting the procedure to
> execute from my application.  The error received when issuing the
> ExecuteNonQuery is "Procedure 'TestProc' expects parameter '@IN',
> which was not supplied.".

> '  Create parameters
> InParam = New SqlParameter("@IN", SqlDbType.Int)
> InParam.Direction = ParameterDirection.Input
> 'Command.Parameters.AddWithValue("@IN", 1)
> ' Add the parameters to the command
> Command.Parameters.Add(InParam)

You neglected to set the value property of InParam.

Jim Wooley
Author
3 Mar 2006 2:47 AM
Virgil
Doh!  I was thinking that the error message was tellnig me it could not
find the param.

Thanks a bunch!