2
我收到一条错误消息Procedure or function Event_Update has too many arguments specified.
试图从C#代码程序功能更新表事件过程或函数Event_Update有太多的参数指定
程序更新
create procedure Event_Update
@id int,
@image varchar(50),
@title varchar(255),
@description varchar(255),
@date date
as
begin
update event set image = @image,[email protected],[email protected],[email protected] where [email protected]
end
事件表
create table event(
id int identity(1,1) primary key,
image varchar(50) not null,
title varchar(255) not null,
description varchar(255) not null,
event_date date not null
)
C#代码
public void update(int id,string title, string image, string events, string date)
{
cmd.CommandText = "Event_Update";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@title", title);
cmd.Parameters.AddWithValue("@image", image);
cmd.Parameters.AddWithValue("@description", events);
cmd.Parameters.AddWithValue("@date", date);
cmd.ExecuteNonQuery();
}
不要重复使用命令对象。为每个要执行的查询创建一个新的查询。也不要重用连接对象。数据库连接池将为您处理,因此只需为一个事务的作用域创建一个连接,并将它们放入'using'语句中,以便将它们处理掉。 – juharr