Results 1 to 5 of 5

Thread: (Resolved) Return Value from Stored Proc

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    (Resolved) Return Value from Stored Proc

    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:
    1. ' TestForm
    2.     Private Sub Button1_Click( _
    3.         ByVal sender As System.Object, _
    4.         ByVal e As System.EventArgs) Handles Button1.Click
    5.  
    6.         Dim myemail As String
    7.         myemail = CStr(GetEmail(1))
    8.         MessageBox.Show(myemail)
    9.  
    10.     End Sub
    11.     Private Function GetEmail(ByVal Store As Integer) As String
    12.  
    13.         Dim cn As SqlConnection = New SqlConnection
    14.         Dim cmd As SqlCommand = New SqlCommand("sproc_GetDMEmail", cn)
    15.         Dim par As SqlParameter = New SqlParameter
    16.  
    17.         cn.ConnectionString = Con
    18.         cn.Open()
    19.  
    20.         par.ParameterName = "@Store"
    21.         par.Direction = ParameterDirection.Output
    22.         par.Value = store
    23.  
    24.         cmd.CommandType = CommandType.StoredProcedure
    25.         cmd.Parameters.Add(par)
    26.         cmd.ExecuteNonQuery()
    27.  
    28.         Return cmd.Parameters.Add(par).Value.ToString
    29.  
    30.     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.
    Last edited by FastEddie; Sep 11th, 2007 at 02:28 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width