在MySql数据库中有一存储过程,如下:
Code
PROCEDURE GetEmployee (employeeID INT)
BEGIN
DECLARE lastName VARCHAR(20);
DECLARE firstName VARCHAR(10);
Declare title VarChar(30);
SELECT LastName, FirstName, Title INTO lastName, firstName, title
FROM Employees WHERE EmployeeID = employeeID;
SELECT lastName,firstName,title;
END
访问如下:
Code
conn.Open();
var command = conn.CreateCommand();
command.CommandText = "`northwind`.`GetEmployee`";
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.AddWithValue("employeeID", 1);
var reader = command.ExecuteReader();
conn.Close();
出现如下错误:
请问各位如何解决?本人已经在网上搜了很久了,谢谢。
返回的结果不只一条;
mysql的参数赋值语句必须是只能够选出一行;
SELECT LastName, FirstName, Title INTO lastName, firstName, title
FROM Employees WHERE EmployeeID = employeeID LIMIT 1 ;
另外,这种赋值语句还有个规矩就是参数名和字段名不能冲突
PROCEDURE GetEmployee (employeeID INT)
@employeeID int
as
BEGIN
DECLARE lastName VARCHAR(20);
DECLARE firstName VARCHAR(10);
Declare title VarChar(30);
SELECT LastName, FirstName, Title INTO lastName, firstName, title
FROM Employees WHERE EmployeeID = employeeID;
SELECT lastName,firstName,title;
END
conn.Open();
var command = conn.CreateCommand();
command.CommandText = "GetEmployee";
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add(New SqlParameter("@employeeID",1));
var reader = command.ExecuteReader();
conn.Close();