Reputation: 47733
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"));
}
Upvotes: 1
Views: 5865
Reputation: 17010
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.
Upvotes: 0
Reputation: 2654
Do your add parameters like this
cmd.Parameters.AddWithValue("@EqId", equipID);
I thinks it's the cleanest way to do it, well kind of :)
Upvotes: 2