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