向sqlCommand添加参数 [英] Adding Parameters to sqlCommand

查看:129
本文介绍了向sqlCommand添加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将参数添加到sqlcommand时,出现错误另一个SqlParameterCollection已包含SqlParameter".在添加参数之前,我尝试通过清除参数.但是仍然会出现错误.我的代码是这样的:

I''m getting an error "The SqlParameter is already contained by another SqlParameterCollection" when adding parameters to the sqlcommand. Before adding the parameters I tried by clearing the parameters. But still error comes. My code is like this:

if (parameterArray != null)
  sqlCommand.Parameters.Clear();
sqlCommand.Parameters.AddRange(parameterArray);

推荐答案

显然您的参数也被另一个sqlcommand使用,这引起了问题.清除所有正在使用它们的sql命令中的参数集合.
Apperently your parameters are used by another sqlcommand too, this is causing the problem. Clear the parameter collections in all the sqlcommands that are using them.


This thread[^] may also give the OP some suggestions.


这篇关于向sqlCommand添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆