此sqlparametercollection不包含parametername为'server#name'的sqlparameter

wydwbb8l  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(206)

我正在尝试使用以下存储过程更新event\ u alerts表:

GO
ALTER procedure [dbo].[servermatch_servers]
@server_name varchar(25)
as
update event_alerts 
set event_alerts.status_alert = (case when master_serverlist.Server_list is null then '0' else '1' 
end)
from event_alerts inner join master_serverlist  on master_serverlist.Server_list = 
event_alerts.server_name where server_name = @server_name

c#代码打击:

using (SqlCommand command3 = new SqlCommand("servermatch_servers", conn1))
{
command3.CommandType = CommandType.StoredProcedure;
command3.Parameters.AddWithValue("@server_name", server);
command3.Parameters[@"server_name"].Direction = ParameterDirection.Input;
command3.ExecuteNonQuery();
}

服务器的值是从字符串中提取出来的,这是服务器名称的值,任何帮助都将不胜感激。提前谢谢

qq24tv8q

qq24tv8q1#

我认为这是罪魁祸首-

command3.Parameters[@"server_name"].Direction = ParameterDirection.Input;

试着把它改成

command3.Parameters["@server_name"].Direction = ParameterDirection.Input;

相关问题