Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLParameter not working properly

I am trying to access a stored procedure and I'm getting an error that says:

Procedure or function 'getbug' expects parameter '@bugID', which was not supplied.

This is my code to call the procedure.

SqlCommand cmd = new SqlCommand("getbug", cn);
cmd.Parameters.Add(new SqlParameter("bugID", bugID));

bugID is set as 1089 (and is type int)

I can't figure out why this won't work.

like image 710
James P. Wright Avatar asked Feb 28 '23 06:02

James P. Wright


2 Answers

Try this instead

SqlCommand cmd = new SqlCommand("getbug", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@bugID", bugID));
like image 142
CResults Avatar answered Mar 08 '23 11:03

CResults


Try adding the "@" to the parameter

SqlCommand cmd = new SqlCommand("getbug", cn);
cmd.Parameters.Add(new SqlParameter("@bugID", bugID));
like image 36
sergiom Avatar answered Mar 08 '23 10:03

sergiom