We help IT Professionals succeed at work.

command.ExecuteNonQuery returns -1

I would like to know what does the value -1 indicate when I execute the command.ExecuteNonQuery  which excutes a stored procedure.

iResult = command.ExecuteNonQuery

iResult shows -1
Watch Question

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.




So how do I know if my stored procdure excuted correctly
If there is an error executing it will throw it.
otherwise you can use an return a specific value in the stored proc if it ran correct.

Executed OK
return 1
return 0

are you updating deleting inserting, or all?


I am inserting records
if you have an identity on the table you can use
return @@IDENTITY;

mycom.CommandType = CommandType.StoredProcedure;
SqlParameter sp = new SqlParameter();
sp.Direction= ParameterDirection.ReturnValue;
string s= mycom.Parameters[0].Value.ToString(); or whatever you need it as

if you need more info let me know

Explore More ContentExplore courses, solutions, and other research materials related to this topic.