我有我創建的StoredProcedure
;StoredProcedure不正確的參數數量(C#)
CREATE DEFINER=`mysqladmin`@`%` PROCEDURE `Alerts_GetAlerts`(IN managerID INT)
BEGIN
SELECT ID, Type, EmpID, ManagerID, HolID
FROM Alerts
WHERE ManagerID = managerID;
END$$
然後我試着從我的C#代碼中調用這個;
using (var con = new MySqlConnection(MySQLConStr))
{
con.Open();
using (MySqlCommand cmd = new MySqlCommand("Alerts_GetAlerts", con))
{
cmd.Parameters.AddWithValue("@managerID", managerID);
using (var dataReader = cmd.ExecuteReader())
{
while (dataReader.Read())
{
var alert = new AlertsModel
{
ID = Convert.ToInt32(dataReader[0]),
Type = Convert.ToInt32(dataReader[1]),
ManagerID = Convert.ToInt32(dataReader[2]),
EmployeeID = Convert.ToInt32(dataReader[3]),
HolidayID = Convert.ToInt32(dataReader[4]),
};
AllAlerts.Add(alert);
}
}
}
return AllAlerts;
}
但是我不斷獲得,Incorrect number of arguments for PROCEDURE sdcdatabase.Alerts_GetAlerts; expected 1, got 0
即使對我來說,似乎我傳遞的經理ID參數通過;
cmd.Parameters.AddWithValue("@managerID", managerID);
我要去哪裏錯了?
嘗試增加'cmd.CommandType = CommandType.StoredProcedure;' – Pikoh
它看起來更像http://stackoverflow.com/a/38706288 – Drew
是經理ID整數類型的變量?不要使用AddWithValue,而是使用ParametersCollection.Add的特定重載,它允許您指定參數的確切數據類型。 – Steve