blog

Home / DeveloperSection / Blogs / Difference between executereader and executenonquery in c#

Difference between executereader and executenonquery in c#

Anonymous User1066 28-Dec-2018

ExecuteNonQuery():

  • It will work with Action Queries only (Create,Alter,Drop,Insert,Update,Delete).
  • Returns the count of rows affected by the Query.
  • The return type is int
  • The return value is optional and can be assigned to an integer variable.

ExecuteReader():

  • It will work with Action and Non-Action Queries (Select)
  • Returns the collection of rows selected by the Query.
  • The return type is DataReader.
  • The return value is compulsory and should be assigned to another object DataReader.

ExecuteScalar():

  • will work with Non-Action Queries that contain aggregate functions.
  • Return the first row and first column value of the query result.
  • The return type is the object.
  • The return value is compulsory and should be assigned to a variable of the required type.

Updated 28-Dec-2018
I am a content writter !

Leave Comment

Comments

Liked By