4

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
  • Just to note, adding "@" to the param doesn't fix the issue. Commented Apr 4, 2010 at 23:07
  • If adding @ doesn't work can you show us some more code. The way you are doing it should work Commented Apr 4, 2010 at 23:08
  • 2
    Ahh, does adding cmd.CommandType = CommandType.StoredProcedure work? I think it defaults to .Text Commented Apr 4, 2010 at 23:10
  • WINNER! Can't accept it as an answer though without you putting it as an answer. :P Commented Apr 4, 2010 at 23:12

3 Answers 3

4

Try this instead

SqlCommand cmd = new SqlCommand("getbug", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@bugID", bugID));
Sign up to request clarification or add additional context in comments.

Comments

3

Try adding the "@" to the parameter

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

Comments

1

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...
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.