c#: ExecuteNonQuery() returns -1

后端 未结 4 1604
-上瘾入骨i
-上瘾入骨i 2021-01-08 00:50

Ive used this method before to return the amount of rows changed. I am it to run an insert method, the insert runs fine in the stored procedure, but the return value from th

4条回答
  •  粉色の甜心
    2021-01-08 01:01

    From Microsoft:

    For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx

    You are probably getting -1 because you are using a stored procedure and not a direct table change

提交回复
热议问题