Wednesday, 18 July 2012

When to Use Execute Reader,Execute Scalar and Execute Non Query?

ExecuteScalar :
               It is used when you just want one single value from one single row, as in:
SELECT Name FROM Users WHERE Id = 123

ExecuteNonQuery :

               It is used for SQL statements that don't return any data (For example, INSERT, UPDATE, DELETE)

ExecuteReader :
              Executes a select query against a database and returns a DataReader object.

No comments:

Post a Comment