欢迎来到.net学习网

欢迎联系站长一起更新本网站!QQ:879621940

您当前所在位置:首页 » Sql随手笔记 » 正文

热门阅读

存储过程return值

创建时间:2011年06月09日 20:46  阅读次数:(5394)
分享到:

存储过程代码如下:

 

ALTER PROCEDURE dbo.testOutput  
    (
    @p1 int ,
    @p2 int OUTPUT,
    @p3 int 
    )   
AS
    /* SET NOCOUNT ON */
    select @p2 = count(*) from testProc where testid between @p1 and @p3
    RETURN @@rowcount
这个存储过程返回2个值,一个是output型参数@p2,另外一个是数据库自带的return值 @@rowcount(语句所影响的行数)。

 

C#程序:

 

            SqlCommand com = new SqlCommand("testOutput",con);
            com.CommandType = CommandType.StoredProcedure;
            SqlParameter p1 = new SqlParameter("@p1",SqlDbType.Int);
            SqlParameter p2 = new SqlParameter("@p2",SqlDbType.Int);
            SqlParameter p3 = new SqlParameter("@p3",SqlDbType.Int);
            SqlParameter rowcount = new SqlParameter("@@rowcount", SqlDbType.Int);   
            p1.Value = int.Parse(textBox2.Text);
            p2.Direction = ParameterDirection.Output; //把p2设置为output型参数
            p3.Value = int.Parse(textBox3.Text);
            rowcount.Direction = ParameterDirection.ReturnValue;//把rowcount类////型设置为returnvalue型
            com.Parameters.Add(p1);
            com.Parameters.Add(p2); 
            com.Parameters.Add(p3);
            com.Parameters.Add(rowcount);
            com.ExecuteNonQuery();
            MessageBox.Show(p2.Value.ToString());  //执行过存储过程以后,output参数p2和@@rowcount就自动返回了值。
            MessageBox.Show(rowcount.Value.ToString());

絒`HN濺 h
来源:
说明:所有来源为 .net学习网的文章均为原创,如有转载,请在转载处标注本页地址,谢谢!
【编辑:Wyf

打赏

取消

感谢您的支持,我会做的更好!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

最新评论

共有评论0条
  • 暂无任何评论,请留下您对本文章的看法,共同参入讨论!
发表评论:
留言人:
内  容:
请输入问题 68+68=? 的结果(结果是:136)
结  果: