Hi..
Any one can help me to explain difference in ExecuteNonQuery() and ExecuteReader method(). I got confusion about these two methods where i should use and which is more beneficial for getting data from data source?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Jul 5, 2011, 1:05 AM
ExecuteReader
Do not use: when database query is going to provide for sure exactly 1 record. It may be getting record by its id (which is PK in the database) - GetOrderById and such. In this case use ExecuteNonQuery with output parameters.
Use: when database query is going to provide a set of records. It may be search or report.
ExecuteNonQuery
Use: when we are talking about a single database record - in Update, Insert, Delete and Get by Id. In all these cases we can use input/output/input-output parameters. Please note that from the application architecture point of view it is also good practices when your Insert and Update stored procedure returns changed record exactly like Get By Id method does.
ExecuteNonQuery():
When the command object is representing DML statments/DDL statments/Stored subprogram then we can go with executenonquery method
ExecuteReader():
When the Select statment returns more than one value then we can go with ExecuteReader()
Valon AdemiPosted Jul 6, 2011, 12:18 AM