日期:2014-05-18  浏览次数:20591 次

SQL中更新是否执行的返回值
存储过程中的几句更新语句
SQL code

    Create Procedure [dbo].[SJJH_UpdateClztbyByBWBH]
    (
    @bwbh varchar(20)
    )
    AS
    Begin
    --set nocount on
    update t_shouli set clzt = '' where yxtywlsh in(@bwbh);
    update t_chengban set clzt = '' where yxtywlsh in(@bwbh);
    update t_shenhe set clzt = '' where yxtywlsh in(@bwbh);
    update t_pizhun set clzt = '' where yxtywlsh in(@bwbh);
    update t_bianjie set clzt = '' where yxtywlsh in(@bwbh);
    END



现在问题是,你输入的参数不管是数据库里有还是没有
C# code

int i =  db.ExecuteNonQuery(dbcmd);
return i;


i都会有返回值,返回5行,但却没有执行

该怎么才能正确判断它是否真正执行了呢?

------解决方案--------------------
@@ROWCOUNT
返回受上一语句影响的行数。

语法
@@ROWCOUNT

返回类型
integer

注释
任何不返回行的语句将这一变量设置为 0 ,如 IF 语句。

示例
下面的示例执行 UPDATE 语句并用 @@ROWCOUNT 来检测是否有发生更改的行。

UPDATE authors SET au_lname = 'Jones'
WHERE au_id = '999-888-7777'
IF @@ROWCOUNT = 0
print 'Warning: No rows were updated'