Unable to recognize stored procedure param

V

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
 
J

Jim Wooley

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 Woole
 
V

Virgil

Doh! I was thinking that the error message was tellnig me it could not
find the param.

Thanks a bunch!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top