Get affected rows on ExecuteNonQuery
ExecuteNonQuery – returns the number of rows affected. SqlCommand comm; // other codes int numberOfRecords = comm.ExecuteNonQuery();
ExecuteNonQuery – returns the number of rows affected. SqlCommand comm; // other codes int numberOfRecords = comm.ExecuteNonQuery();
Based on 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 … Read more
As suggested by Aaron, a stored procedure would make it faster because it saves Sql Server the work of compiling your SQL batch. However, you could still go with either approach: ExecuteScalar or ExecuteNonQuery. IMHO, the performance difference between them is so small, that either method is just as “proper”. Having said that, I don’t … Read more