According to MSDN
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.
To summarize, if none of your rows are affected by your stored procedure, you're going to return a value of 0
If you have SET NOCOUNT ON
in your stored procedure or a rollback occurs, you will always get a return value of -1
If you want to see if an error has occurred, you would need to put a try catch in your method. Obviously here I'm catching a generic exception. You would want to catch the specific exception and wrap the opening and the closing of your connection in a using statement to dispose of the connection when a failure occurs.
int retryCount = 0;
using (SqlCommand myCommand = new SqlCommand("MyStoredProcedure", new SqlConnection("Server=.;Database=MyDatabase;Trusted_Connection=True;")))
{
while (retryCount < 10)
{
try
{
if (myCommand.Connection.State == ConnectionState.Closed)
{
myCommand.Connection.Open();
}
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
retryCount++;
System.Threading.Thread.Sleep(1000);
}
}
}