I have used this method before to return the number of rows. I run the insert method, the insert works fine in the stored procedure, but the return value from 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 am I getting -1 instead of the actual number of rows?
c # executenonquery
Funky
source share