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