How can I get the number of records affected by a stored procedure?

前端 未结 6 1996
轮回少年
轮回少年 2020-12-04 20:32

For INSERT, UPDATE and DELETE SQL statements executed directly against the database, most database providers return the count of rows

6条回答
  •  萌比男神i
    2020-12-04 21:28

    Turns out for me that SET NOCOUNT ON was set in the stored procedure script (by default on SQL Server Management Studio) and SqlCommand.ExecuteNonQuery(); always returned -1.

    I just set it off: SET NOCOUNT OFF without needing to use @@ROWCOUNT.

    More details found here : SqlCommand.ExecuteNonQuery() returns -1 when doing Insert / Update / Delete

提交回复
热议问题