输出/输入参数的存储过程返回计数

时间:2016-04-19 00:58:45

标签: c# sql

我想获取存储过程返回的值。我在SQL中执行,一切正常,但是当从C#调用时,我得到0.

CREATE PROCEDURE [dbo].[USerFilter_SP_MatchUserFilter](
@User varchar(50), 
@Car varchar(50), 
@Part varchar(50), 
@State varchar(50), 
@Year varchar(50) )
AS 
Begin
SELECT COUNT(*)
FROM
(

    /* Statement here request row count */

)X
End

1 个答案:

答案 0 :(得分:0)

尝试设置NOCOUNT:

https://msdn.microsoft.com/en-nz/library/ms189837.aspx

我认为你发现的事情就是“消息”和#39; SSMS中的窗口,您将获得内部查询的行计数返回。这可以填补C#一点点。 SET NOCOUNT ON禁止这样做,所以你只返回好东西:

CREATE PROCEDURE [dbo].[USerFilter_SP_MatchUserFilter](
  @User varchar(50), 
  @Car varchar(50), 
  @Part varchar(50), 
  @State varchar(50), 
  @Year varchar(50) )
AS 
Begin

   -- SET NOCOUNT ON added to prevent extra result sets from
   -- interfering with SELECT statements.
   SET NOCOUNT ON;

   SELECT COUNT(*)
   FROM
   (
       /* Statement here request row count */
   )X
End