I am running SP which does not return any rows or data , than in that case which is more efficient
executeScalar() or executeNonQuery()
views:
250answers:
4ExecuteScalar returns a single value as a result of the query in the command object, therefor the other would be better to use. ExecuteNonQuery does not return a value (except rows effected by the query).
Im not sure it matters much either way, executeNonQuery will have marginally less object construction done in it, but the difference will be negligible in most cases.
If you don't want to read a value you should use executeNonQuery. It has nothing to do with efficiency. You should do it because that's the correct way to do it. Using executeScalar here is just wrong.
It's probably also faster, but that's not the point. If you are firing so many queries that this minor performance detail makes a difference something is wrong with your query.
Executescalar returns a value and executeNonquery is used generally for inserting , updating etc. In this case as you are not returning any values you should use ExecuteNonQuery.