views:

71

answers:

3

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.

+4  A: 

Try this instead

SqlCommand cmd = new SqlCommand("getbug", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@bugID", bugID));
CResults
+2  A: 

Try adding the "@" to the parameter

SqlCommand cmd = new SqlCommand("getbug", cn);
cmd.Parameters.Add(new SqlParameter("@bugID", bugID));
sergiom
+1  A: 

More code will help. Here's a couple of ideas though.

If you're calling a stored procedure, you need to specify the CommandType. Also, you can use the AddWithValue method to shorten your code.

using (var cn = new SqlConnection("your connection string"))
{
    using (var cmd = new SqlCommand("getbug", cn))
    {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@bugID", bugID);

        //etc...
    }
}
Aaron Daniels