Ive used this method before to return the amount of rows changed. I am it to run an insert method, the insert runs fine in the stored procedure, but the return value from the ExecuteNonQuery always returns -1.
Here is my C# code:
int ret = 0;
using (SqlConnection conn = new SqlConnection(this.ConnectionString))
{
using (SqlCommand cmd = new SqlCommand(QueryName, conn))
{
conn.Open();
if (Params != null)
cmd.Parameters.AddRange(Params);
cmd.CommandType = CommandType.StoredProcedure;
ret = cmd.ExecuteNonQuery();
conn.Close();
}
}
return ret;
Why do I get -1 instead of the actual number of rows changed?