的ExecuteNonQuery()返回-1总是 [英] ExecuteNonQuery() returns -1 always

查看:388
本文介绍了的ExecuteNonQuery()返回-1总是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个存储过程来插入表中的一些价值。

I am using a stored procedure to insert some value in table.

CREATE PROCEDURE [dbo].[Sp_InsertValue]
@Val1 as nvarchar(50)
@Val2 as nvarchar(50)
as
BEGIN
    IF NOT EXISTS(SELECT * FROM @mytable WHERE ID=@Val1)
    INSERT INTO @mytable VALUES(@VAL2)
END

我使用的ExecuteNonQuery()使用C#调用ASP.NET此存储过程。它工作正常,没有任何问题,它,如果他们不存在插入值。问题是,cmd.ExecuteNonQuery()总是返回-1。我预计,如果一个记录被插入,它应该返回1和0,如果没有,对不对?

I am using ExecuteNonQuery() to call this stored procedure in ASP.NET using C#. It works fine, no issues, it inserts values if they don't exist. The issue is that cmd.ExecuteNonQuery() always return -1. I expect if a record is inserted, it should return 1, and 0 if not, right?

推荐答案

检查你不在存储过程中T的SET NOCOUNT ON。这将停止被返回影响的行数。从字面上看NOCOUNT为ON。

Check that you don't have "SET NOCOUNT ON" in your stored procedure. This will stop the number of affect rows be returned. Literally 'NoCount' is ON.

默认的反应永远是-1,在这种情况下。

Default response will always be '-1' in this situation.

这篇关于的ExecuteNonQuery()返回-1总是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆