我有一个StoredProcedure
我就是这样创建的;
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
即使对我来说,似乎我正在通过managerID参数;
cmd.Parameters.AddWithValue("@managerID", managerID);
我哪里错了?
答案 0 :(得分:-1)
试试这段代码
using (var con = new MySqlConnection(MySQLConStr))
{
con.Open();
using (MySqlCommand cmd = new MySqlCommand("Alerts_GetAlerts(@managerID)", 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;
}