[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2660
  • Last Modified:

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
0
countrymeister
Asked:
countrymeister
  • 3
  • 3
1 Solution
 
burakiewiczCommented:
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.
0
 
countrymeisterAuthor Commented:
Thanks
0
 
countrymeisterAuthor Commented:
So how do I know if my stored procdure excuted correctly
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
burakiewiczCommented:
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
didnt
return 0

are you updating deleting inserting, or all?
0
 
countrymeisterAuthor Commented:
I am inserting records
0
 
burakiewiczCommented:
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;
mycom.Parameters.Add(sp);
mycom.ExecuteNonQuery();
string s= mycom.Parameters[0].Value.ToString(); or whatever you need it as

if you need more info let me know
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now