Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExecuteNonQuery returns -1

I have a stored procedure and it returns a string value, and I have to execute this SP using ExecuteNonQuery statement. 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?

like image 947
Sivajith Avatar asked Jul 16 '12 06:07

Sivajith


People also ask

What is returned from the ExecuteScalar () method?

ExecuteScalar() Method:ExecuteScalar() method is used to retrieve a single value from database. It executes the defined query and returns the value in the first column of the first row in the selected result set and ignores all other columns and rows in the result set.

What is use of ExecuteScalar () method?

Use the ExecuteScalar method to retrieve a single value (for example, an aggregate value) from a database. This requires less code than using the ExecuteReader method, and then performing the operations that you need to generate the single value using the data returned by a SqlDataReader.

Why ExecuteNonQuery is not working?

You have to assign the connection for the command object. Your code is vulnerable to SQL injection. Also, you should use a using block with classes that implement the IDisposable interface, especially with the SqlConnection class in order to close the connection in case of an exception.

What is ExecuteNonQuery ado net?

ExecuteNonQuery method is used to execute SQL Command or the storeprocedure performs, INSERT, UPDATE or Delete operations. It doesn't return any data from the database. Instead, it returns an integer specifying the number of rows inserted, updated or deleted.


1 Answers

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.

like image 137
vonPryz Avatar answered Sep 26 '22 07:09

vonPryz