Procedure or function expects parameter which was not supplied.
Recently I got this error when doing a ADO.NET database call using ExecuteReader.
Procedure or function expects parameter '@myid', which was not supplied.
Actually, the error is kind of misleading. Why because I clearly adding my parameter @myid to the SqlParameters collection of the SqlCommand.
cmd.Parameters.Add(“@myid”,1)
Yes, actually, I had to pass an hard-coded 1 as a value. @myid is defined as int in my database.
All top search suggested me that I need to set CommandType.StoredProcedure for my command, which again I was doing. After some more debugging and looking more deeply into the error I saw it was @myid was being considered as SqlDbType.BigInt. I don’t know why and so I tried this:
int myid=1;
cmd.Parameters.Add(“@myid”,myid)
And to my wonder the error disappeared. I reverted back my changes and it started throwing me error.
Now before writing this post, I thought I will give you a screenshot of the error and so I again ran the program with my original code and this time I don’t get the error. So not sure what happened.
If you are getting this error, this is one thing to try and see if it resolves the issue for you.
Thanks for reading.