Jan 29th, 2011, 11:09 AM
#1
Thread Starter
PowerPoster
[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:
CREATE PROCEDURE [dbo].[sp_GetPhoneInfoByName]
@ClientName VARCHAR(50)
AS
BEGIN
SET NOCOUNT ON;
SELECT ClientInformation.ClientInfoID_PK,
ClientInformation.ClientName,
ClientInformation_PhoneNumbers.ClientPhoneNumber,
ClientInformation_PhoneNumbers.ClientInfoID_PKFK,
ClientInformation_PhoneNumbers.PhoneNumberTypeID_PKFK,
ClientInformation_PhoneNumberType.PhoneNumberTypeID_PK,
ClientInformation_PhoneNumberType.PhoneNumberTypeName
FROM ClientInformation
INNER JOIN ClientInformation_PhoneNumbers
ON ClientInformation.ClientInfoID_PK = ClientInformation_PhoneNumbers.ClientInfoID_PKFK
INNER JOIN ClientInformation_PhoneNumberType
ON ClientInformation_PhoneNumberType.PhoneNumberTypeID_PK = ClientInformation_PhoneNumbers.PhoneNumberTypeID_PKFK
WHERE ClientInformation.ClientName = @ClientName
END
The stored procedure created without issue. In my code, I have the following:
vb Code:
'Set the attributes for the SQLCommand.
With MySQLCommand
.Connection = SetDatabaseConnection
.CommandType = CommandType.StoredProcedure
.CommandText = "sp_GetPhoneInfoByName"
.Parameters.AddWithValue("@ClientName", "'" & cboClientName.Text.Trim.ToString & "'")
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
Jan 29th, 2011, 11:40 AM
#2
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?
Jan 29th, 2011, 11:42 AM
#3
Thread Starter
PowerPoster
Re: Procedure or function expects parameter which was not supplied.
Originally Posted by
kevininstructor
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.
Jan 29th, 2011, 11:47 AM
#4
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?
Jan 29th, 2011, 11:55 AM
#5
Thread Starter
PowerPoster
Re: Procedure or function expects parameter which was not supplied.
Originally Posted by
kevininstructor
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!
Jan 29th, 2011, 11:57 AM
#6
Thread Starter
PowerPoster
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.
Jan 29th, 2011, 11:59 AM
#7
Thread Starter
PowerPoster
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:
.Parameters.AddWithValue("@ClientName", cboClientName.Text.Trim.ToString)
and it now works. Strange.
Jan 29th, 2011, 12:06 PM
#8
Re: Procedure or function expects parameter which was not supplied.
Originally Posted by
BrailleSchool
OK, i got it resolved. I closed out VB Pro and then relaunched. Changed the line to:
vb Code:
.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.
Jan 29th, 2011, 12:36 PM
#9
Thread Starter
PowerPoster
Re: Procedure or function expects parameter which was not supplied.
Originally Posted by
kevininstructor
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.
Jan 29th, 2011, 01:11 PM
#10
Re: Procedure or function expects parameter which was not supplied.
Originally Posted by
BrailleSchool
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.
Jan 29th, 2011, 08:54 PM
#11
Thread Starter
PowerPoster
Re: Procedure or function expects parameter which was not supplied.
Originally Posted by
kevininstructor
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
Forum Rules
Click Here to Expand Forum to Full Width