2013-09-26 34 views
-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

我的心理調試能力告訴我,你應該使用''@dateofbirth'' – SWeko

+2

btw;而不是''@birthdate'';只有'throw'的'try' /'catch'沒有增加任何內容:你可能會刪除所有這些。 –

+2

但是你絕對**應該擁有的是圍繞'objconn'使用'' - 此時你並沒有正確地關閉連接,並且你會很快填滿連接池(應該*也是*使用'圍繞'objcommand',但那一個只是「壞」,而不是「致命」) –

回答

1

使用SWeko的評論:

替換此行:

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

與:

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

兩種可能性:

  • 參數名具有錯字(其可以包括區分大小寫如果數據庫被配置用於那);如果是這樣:狐狸錯字
  • 的參數值是null(這意味着它沒有得到根本發送);如果是這樣DBNull.Value

應用兩種可能性在一起替換:

objcommand.Parameters.AddWithValue("dateofbirth", 
    ((object)EBAL.birthdate)??DBNull.Value); 
0

你在你的SP參數名是@dateofbirth並正在從上面的代碼通過@birthdate。所以把它改爲@dateofbirth

相關問題