I am trying to get a value back from a stored procedure but I haven't been able to get the code right and the samples I have looked at have added more confusion. Here is what I have:
vb Code:
' TestForm Private Sub Button1_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim myemail As String myemail = CStr(GetEmail(1)) MessageBox.Show(myemail) End Sub Private Function GetEmail(ByVal Store As Integer) As String Dim cn As SqlConnection = New SqlConnection Dim cmd As SqlCommand = New SqlCommand("sproc_GetDMEmail", cn) Dim par As SqlParameter = New SqlParameter cn.ConnectionString = Con cn.Open() par.ParameterName = "@Store" par.Direction = ParameterDirection.Output par.Value = store cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add(par) cmd.ExecuteNonQuery() Return cmd.Parameters.Add(par).Value.ToString End Function
The error I get is The formal parameter "@Store" was not declared as an OUTPUT parameter, but the actual parameter passed in requested output.




Reply With Quote