0

I have stored proc that returns various integers based on few conditions. It does not has any Select statement. when I use

SqlHelper.ExecuteNonQuery("ConString",CommandType.StoredProcedure,"ProcName")

this ExecuteNonQuery returns -1. What does -1 mean here?

Samuel A C
  • 406
  • 3
  • 16
  • 2
    Where is SqlHelper coming from? Is it your own class, because I can find no reference to it anywhere. Perhaps taking a look at that code might help you out. – Silvermind Sep 20 '18 at 08:59
  • You should use the out parameters of the stored-procedure. Just google it and you find: https://stackoverflow.com/questions/10905782/using-stored-procedure-output-parameters-in-c-sharp – Tim Schmelter Sep 20 '18 at 09:03
  • @Silvermind it is a wrapper of Sqlcommand, a library I downloaded from Github.. – Samuel A C Sep 20 '18 at 09:48

1 Answers1

1

Assuming SqlHelper is a wrapper for SqlCommand...

The documentation states:

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, depending on your query / proc, it either:

  • is not an UPDATE, INSERT or DELETE statement or can't affect any rows
  • has caused a rollback to occur
Diado
  • 2,229
  • 3
  • 18
  • 21