我有這樣的C#代碼調用存儲過程:誤差存儲過程代碼
using (SqlConnection myConnection = new SqlConnection(Utility.ConnString))
{
myConnection.Open();
using (SqlCommand myCommand = new SqlCommand(AddScanLocation_Proc, myConnection))
{
myCommand.Parameters.AddWithValue("@LocationQr", string.IsNullOrEmpty(LocationQr) ? "" : LocationQr);
myCommand.Parameters.AddWithValue("@LocationNfc", string.IsNullOrEmpty(LocationNfc) ? "" : LocationNfc);
myCommand.Parameters.AddWithValue("@LocationMachineName", LocationMachineName);
myCommand.Parameters.AddWithValue("@LocationName", LocationName);
myCommand.Parameters.AddWithValue("@IsLastStop", IsLastStop);
myCommand.Parameters.AddWithValue("@Active", Active);
IAsyncResult res = myCommand.BeginExecuteNonQuery();
while (!res.IsCompleted) { }
int response = myCommand.EndExecuteNonQuery(res);
if (response > 0)
toReturn = true;
}
}
我每次執行的代碼,我得到一個錯誤,告訴我
過程或函數「AddScanLocation」期望參數'@LocationMachineName',它沒有提供。
我已經調試了幾個小時的代碼,一切都正確輸入,並且變量不爲空或空的,但它不斷拋出一個錯誤
任何建議將不勝感激!
我的建議,不要使用AddWithValue。 – DavidG 2014-10-09 22:22:23
@LocationMachineName的值和類型是什麼? – Ciaran 2014-10-09 22:23:03
你的連接字符串是什麼?它包含'AttachDBFIleName'嗎?如果是這樣,請參閱[本博文](http://blogs.sqlsentry.com/aaronbertrand/bad-habits-attachdbfilename/)。此外,你說錯誤引用'AddScanLocation',但代碼實際上調用'AddScanLocation_Proc' - 錯字?或者你有兩個不同的對象,一個帶有無用的'_Proc'後綴,可能有不同的簽名? – 2014-10-09 22:23:42