111,129
社区成员
发帖
与我相关
我的任务
分享CREATE PROCEDURE [dbo].[sp_add]
(
@x int,
@y int,
@r int output
)
AS
BEGIN
SET NOCOUNT ON;
set @r = @x + @y;
return 0;
END
调用方式:
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = xxxx;
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_add";
SqlParameter[] ps = new SqlParameter[4];
ps[0] = new SqlParameter("@x", 1);
ps[1] = new SqlParameter("@y", 2);
ps[2] = new SqlParameter("@r", SqlDbType.Int);
ps[2].Direction = ParameterDirection.Output;
ps[3] = new SqlParameter();
ps[3].SqlDbType = SqlDbType.Int;
ps[3].Direction = ParameterDirection.ReturnValue;
cmd.Parameters.AddRange(ps);
int r = cmd.ExecuteNonQuery();
Console.WriteLine(string.Format("@r={0},存储过程返回:{1},ExecuteNonQuery返回:{2}", ps[2].Value, ps[3].Value, r));
}
}
看一下都返回了此什么。