简体   繁体   中英

ExecuteNonQuery returns -1

I have a stored procedure and it returns a value, and I have to execute this SP using ExecuteNonQuery statement. 值,我必须使用ExecuteNonQuery语句执行此SP。 When I execute this, I get -1 as the return value.

I never used SET NOCOUNT ON . How can I get the return value? I did not declare the return value as OUTPUT -- just SELECT @VARIABLENAME . How can I get the value using ExecuteNonQuery ?

ExecuteNonQuery is used to execute queries that return only the number of rows affected (though output parameters can be populated). -1 means that no rows were affected or you have set nocount on.

Use another an API call if you need to read data from the sproc.

If you are only grabbing one value I would use the ExecuteScalar command if you are in a .Net Langauge. I know that Java and the like has an equivalent.

http://msdn.microsoft.com/en-us/ibrary/system.data.sqlclient.sqlcommand.executescalar.aspx

ExecuteNonQuery can get return data, if you have Output paramaters in your SP. This article explains how.

http://msdn.microsoft.com/en-us/library/80x06z3b(v=VS.71).aspx

Though again if you are just returning a string ExecuteScalar is simpler to use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM