-2

我尝试更新记录时出错

过程或函数(sp_UpdateEmp)需要(@dateofbirth)未提供的参数

这是我的功能

public void Updatedata(Bussinessobject.BO EBAL)
{
  objconn = new SqlConnection(connectionstring);
  if (objconn.State != ConnectionState.Open)
  try
  {
    objconn.Open();
    objcommand = new SqlCommand("sp_UpdateEmp", objconn);
    objcommand.CommandType = CommandType.StoredProcedure;
    objcommand.Parameters.AddWithValue("@id", EBAL.id);
    objcommand.Parameters.AddWithValue("@fname", EBAL.fname);
    objcommand.Parameters.AddWithValue("@lname", EBAL.lname);
    objcommand.Parameters.AddWithValue("@address", EBAL.address);
    objcommand.Parameters.AddWithValue("@phone", EBAL.phone);
    objcommand.Parameters.AddWithValue("@birthdate", EBAL.birthdate);
    objcommand.Parameters.AddWithValue("@hiredate", EBAL.datehire);
    objcommand.Parameters.AddWithValue("@gender", EBAL.gender);

    objcommand.ExecuteNonQuery();
  }
  catch
  {
    throw;
  }
}
4

3 回答 3

1

使用 SWeko 的评论:

替换这一行:

objcommand.Parameters.AddWithValue("@birthdate", EBAL.birthdate);

和:

objcommand.Parameters.AddWithValue("@dateofbirth", EBAL.birthdate);
于 2013-09-26T09:53:04.363 回答
1

两种可能:

  • 参数名称有错别字(如果数据库为此配置,则可能包括区分大小写);如果是这样:消除错字
  • 参数值为null(这意味着它根本不会被发送);如果是这样,请替换为DBNull.Value

将这两种可能性一起应用:

objcommand.Parameters.AddWithValue("dateofbirth",
    ((object)EBAL.birthdate)??DBNull.Value);
于 2013-09-26T09:53:44.690 回答
0

您在 sp 中的参数名称是@dateofbirth并且您是@birthdate从上面的代码传递的。所以改成@dateofbirth.

于 2013-09-26T09:54:14.433 回答