【发布时间】:2012-05-10 01:00:44
【问题描述】:
我在尝试通过存储过程更新数据库中的一行时遇到此错误
过程或函数“sp_A_Update”需要参数“@Misc”,但未提供。
但我已经提供了这个:
command.Parameters.AddWithValue("@Misc", inspection.Misc);
这是我的整个代码,去掉了其他参数来缩短
using (SqlCommand command = new SqlCommand("sp_Agent_Inspection_Update", new SqlConnection (Configuration.ConnectionString)))
{
command.CommandType = CommandType.StoredProcedure;
PropertyInfo[] propertyInfo = inspection.GetType().GetProperties();
command.Parameters.AddWithValue("@Misc", inspection.Misc);
(lots of other params here...)
command.Parameters.AddWithValue("@RepairNotes", inspection.RepairNotes);
// OPEN CONNECTION
command.Connection.Open();
// EXECUTE QUERY
int rowsAffected = command.ExecuteNonQuery();
command.Connection.Close();
return Boolean.Parse(rowsAffected.ToString());
}
有人有什么想法吗?
【问题讨论】:
-
错误显示“sp_A_Update”,但代码显示“sp_Agent_Inspection_Update”。你确定你在调试正确的代码吗?
-
我没有看到你在任何地方定义
inspection。可能是我对 C# 不了解,但也许你需要定义它? -
你能发布至少部分存储过程吗?
-
我会假设 sp_Agent_Inspection_Update 中的 SQL 执行 sp_A_Update,它没有将参数 @Misc 传递给它。
-
我似乎记得您需要确保在代码中添加参数的顺序与它们在 SQL 存储过程定义中出现的顺序相同。