首页 新闻 会员 周边 捐助

求助:MySql存储过程的访问

0
悬赏园豆:50 [已解决问题] 解决于 2009-07-01 12:32

在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();

出现如下错误:

请问各位如何解决?本人已经在网上搜了很久了,谢谢。

麦舒的主页 麦舒 | 菜鸟二级 | 园豆:452
提问于:2009-06-30 20:03
< >
分享
最佳答案
0

返回的结果不只一条;

mysql的参数赋值语句必须是只能够选出一行;

SELECT LastName, FirstName, Title INTO lastName, firstName, title 
FROM Employees WHERE EmployeeID = employeeID
LIMIT 1 ;
另外,这种赋值语句还有个规矩就是参数名和字段名不能冲突
winzheng | 大侠五级 |园豆:8797 | 2009-07-01 11:50
其他回答(1)
0

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();

LoujaDy | 园豆:908 (小虾三级) | 2009-06-30 20:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册