Results 1 to 11 of 11

Thread: [RESOLVED] Procedure or function expects parameter which was not supplied.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] Procedure or function expects parameter which was not supplied.

    Hi all,

    I was working on this thread in regard to DataRelations on multiple tables. If I use CommandType = CommandType.Text, the code does as expected. However, I decided to take the SQL query and throw it into a stored proc. I then changed my code to use the stored procedure and I get the error as per the title of this thread.

    The stored procedure is as follows:
    vb Code:
    1. CREATE PROCEDURE [dbo].[sp_GetPhoneInfoByName]
    2. @ClientName VARCHAR(50)
    3. AS
    4. BEGIN
    5. SET NOCOUNT ON;
    6.  
    7. SELECT ClientInformation.ClientInfoID_PK,
    8.        ClientInformation.ClientName,
    9.        ClientInformation_PhoneNumbers.ClientPhoneNumber,
    10.        ClientInformation_PhoneNumbers.ClientInfoID_PKFK,
    11.        ClientInformation_PhoneNumbers.PhoneNumberTypeID_PKFK,
    12.        ClientInformation_PhoneNumberType.PhoneNumberTypeID_PK,
    13.        ClientInformation_PhoneNumberType.PhoneNumberTypeName
    14. FROM ClientInformation
    15. INNER JOIN ClientInformation_PhoneNumbers
    16. ON ClientInformation.ClientInfoID_PK = ClientInformation_PhoneNumbers.ClientInfoID_PKFK
    17. INNER JOIN ClientInformation_PhoneNumberType
    18. ON ClientInformation_PhoneNumberType.PhoneNumberTypeID_PK = ClientInformation_PhoneNumbers.PhoneNumberTypeID_PKFK
    19. WHERE ClientInformation.ClientName = @ClientName
    20. END

    The stored procedure created without issue. In my code, I have the following:
    vb Code:
    1. 'Set the attributes for the SQLCommand.
    2.                         With MySQLCommand
    3.                             .Connection = SetDatabaseConnection
    4.                             .CommandType = CommandType.StoredProcedure
    5.                             .CommandText = "sp_GetPhoneInfoByName"
    6.                             .Parameters.AddWithValue("@ClientName", "'" & cboClientName.Text.Trim.ToString & "'")
    7.                         End With

    When I use the SQL Profiler, I see that NULL is being passed to the stored procedure. I have looked online and haven't been able to find an answer. Anyone here have any ideas? Thanks.
    Attached Images Attached Images  

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Procedure or function expects parameter which was not supplied.

    Could there be any apostrophes embedded in the param value?
    Have you tried AddWithValue w/o apostrophes wrapping the value?

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Procedure or function expects parameter which was not supplied.

    Quote Originally Posted by kevininstructor View Post
    Could there be any apostrophes embedded in the param value?
    Have you tried AddWithValue w/o apostrophes wrapping the value?
    tried that and also just cboClientName.Text and get the same error.

  4. #4
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Procedure or function expects parameter which was not supplied.

    Have you tried hard coding a value for the param into AddWithValue

    Code:
    .Parameters.AddWithValue("@ClientName", "'SomeValue'")
    or 
    .Parameters.AddWithValue("@ClientName", "SomeValue")
    Do you get the same result?

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Procedure or function expects parameter which was not supplied.

    Quote Originally Posted by kevininstructor View Post
    Have you tried hard coding a value for the param into AddWithValue

    Code:
    .Parameters.AddWithValue("@ClientName", "'SomeValue'")
    or 
    .Parameters.AddWithValue("@ClientName", "SomeValue")
    Do you get the same result?
    Nope, I tried that too and it works if I hard code it. Weird because the ComboBox has a value, so not sure why it's passing NULL to the SPROC!

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Procedure or function expects parameter which was not supplied.

    i even tried assigning the ComboBox to a string variable and then using the string variable name, still got the error.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Procedure or function expects parameter which was not supplied.

    OK, i got it resolved. I closed out VB Pro and then relaunched. Changed the line to:
    vb Code:
    1. .Parameters.AddWithValue("@ClientName", cboClientName.Text.Trim.ToString)

    and it now works. Strange.

  8. #8
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Procedure or function expects parameter which was not supplied.

    Quote Originally Posted by BrailleSchool View Post
    OK, i got it resolved. I closed out VB Pro and then relaunched. Changed the line to:
    vb Code:
    1. .Parameters.AddWithValue("@ClientName", cboClientName.Text.Trim.ToString)

    and it now works. Strange.
    Only strange that you had to close VS, it makes sense that no delimitor was needed.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Procedure or function expects parameter which was not supplied.

    Quote Originally Posted by kevininstructor View Post
    Only strange that you had to close VS, it makes sense that no delimitor was needed.
    Yep, sure is. VS gets weird on me sometimes.

  10. #10
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Procedure or function expects parameter which was not supplied.

    Quote Originally Posted by BrailleSchool View Post
    Yep, sure is. VS gets weird on me sometimes.
    Next time something like this happens try "cleaning" the project then "rebuild" instead of closing VS.

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Procedure or function expects parameter which was not supplied.

    Quote Originally Posted by kevininstructor View Post
    Next time something like this happens try "cleaning" the project then "rebuild" instead of closing VS.
    I always clean before rebuild.

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