I am new to C # and I am trying to set up a stored procedure call in my database that takes one parameter.
I get the error message "Procedure or function" SP_getName "expects parameter" @username ", which was not specified."
My stored procedure works fine when I supply it with a parameter, and I run it through SQL Management Studio.
GO DECLARE @return_value int EXEC @return_value = [dbo].[SP_getName] @username = 'bob101' SELECT 'Return Value' = @return_value GO
However, when I try to call it, the error is related to the way I pass this parameter, but I can not determine what the problem is.
//create a sql command object to hold the results of the query SqlCommand cmd = new SqlCommand(); //and a reader to process the results SqlDataReader reader; //Instantiate return string string returnValue = null; //execute the stored procedure to return the results cmd.CommandText = "SP_getName"; //set up the parameters for the stored procedure cmd.Parameters.Add("@username", SqlDbType.NVarChar).Value = "bob101"; cmd.CommandType = CommandType.Text; cmd.Connection = this.Connection; // then call the reader to process the results reader = cmd.ExecuteReader();
Any help in determining my mistake would be greatly appreciated!
I also tried looking at these two posts, but I had no luck:
A stored procedure or function expects a parameter that is not specified
A procedure or function expects a parameter that has not been provided
Thanks!
source share