1

Cannot figure out why I keep getting

An SqlParameter with ParameterName is not contained by this SqlParameterCollection

when I've been pulling and calling procs like this fine in other methods.

The proc does have the one param @EqId in that casing.

List<string> equipTypes = new List<string>();

Database db = DatabaseFactory.CreateDatabase("OurDBName");
DbCommand cmd = db.GetStoredProcCommand("Get_EquipTypes_By_ID");

db.DiscoverParameters(cmd);
cmd.Parameters["@EqId"].Value = equipID;

using (IDataReader objReader = db.ExecuteReader(cmd))
{
   while (objReader.Read())
      equipTypes.Add(DataUtility.GetStringFromReader(objReader, "Data"));
}
1
  • 2
    Why would you even use DiscoverParameters? That is an extra round trip, yet you already know the name. That is for tools that probe procs. Commented Oct 28, 2011 at 17:07

2 Answers 2

2

Do your add parameters like this

 cmd.Parameters.AddWithValue("@EqId", equipID);

I thinks it's the cleanest way to do it, well kind of :)

Sign up to request clarification or add additional context in comments.

Comments

0

First off, I would not discover parameters when you are aware of the parameters. Since you are doing this, examine the parameter collection and make sure the parameter is being discovered. Fater you have that figured out, I would aim for something more like what Greg has suggested.

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.