此 SqlParameterCollection 不包含具有 ParameterName 的 SqlParameter
不明白为什么我不断
此参数不包含具有 ParameterName 的 SqlParameter Sql参数集合
当我在其他方法中像这样拉取和调用过程时,
就很好了。该过程在该外壳中确实有一个参数@EqId。
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"));
}
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"));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样添加参数
我认为这是最干净的方法,很好:)
Do your add parameters like this
I thinks it's the cleanest way to do it, well kind of :)
首先,当你知道参数时我不会发现参数。由于您正在执行此操作,请检查参数集合并确保正在发现该参数。一旦你明白了这一点,我的目标就会更像格雷格所建议的那样。
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.