Difference between ExecuteScalar ExecuteReader ExecuteNonQuery



ExecuteNonQuery:  is typically used when there is nothing returned from the Sql statements like insert ,update, delete operations.


cmd.ExcecuteNonQuery();

ExecuteScalar:

It will be used when Sql query returns single value.

Ex :  to get single value from Sql statements like count , sum , average, or other aggregated value from a database.


Int b = cmd.ExcecuteScalar();

ExecuteReader

It will be used when Sql query or Stored Procedure returns multiple rows/columns


SqlDataReader dr = cmd.ExecuteReader();

 

Labels: difference between executequery and executenonquery, When to use ExecuteScalar, ExecuteReader, ExecuteNonQuery, difference between executequery and executenonquery in c#, executescalar executereader executenonquery





Recent Posts

Categories
Subscribe

Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker