存储过程很简单返回一个数字,
1 CREATE PROCEDURE up_GetReturnValue
2 @a int,
3 @b int
4 AS
5 BEGIN
6 SET NOCOUNT ON;
7
8 RETURN @a+@b
9 END
10 GO
2 @a int,
3 @b int
4 AS
5 BEGIN
6 SET NOCOUNT ON;
7
8 RETURN @a+@b
9 END
10 GO
获取存储过程返回值的方法:
1 SqlParameter returnPara = new SqlParameter();
2 returnPara.ParameterName = "@ReturnValue";
3 returnPara.Direction = ParameterDirection.ReturnValue;
4 returnPara.DbType = DbType.Int;
5 cmd.Parameters.Add(returnPara);
6
7 cmd.ExecuteNonQuery("up_GetReturnValue", CommandType.StoredProcedure);
8 return Convert.ToInt(returnPara.Value);
2 returnPara.ParameterName = "@ReturnValue";
3 returnPara.Direction = ParameterDirection.ReturnValue;
4 returnPara.DbType = DbType.Int;
5 cmd.Parameters.Add(returnPara);
6
7 cmd.ExecuteNonQuery("up_GetReturnValue", CommandType.StoredProcedure);
8 return Convert.ToInt(returnPara.Value);