Home > DeveloperSection > Blogs > ExecuteNonQuery, ExecuteReader and ExecuteScalar Methods in C#

ExecuteNonQuery, ExecuteReader and ExecuteScalar Methods in C#


C# C# 
Ratings:
0 Comment(s)
 3844  View(s)
Rate this:

ExecuteNonQuery, ExecuteReader and ExecuteScalar Methods in C#

ExecuteNonQuery Method:

This method is commonly used for update, insert and delete statements, where the only returned value is the number of record affected.

Namespace: System.Data.SqlClient

Assembly: System.Data (in System.Data.dll)

Return Value Type: System.Int32

ExecuteReader Method:

This method executes the command and returns a typed data reader object, depending on the provider is used. The object returned can be used to iterate through the record(s) returned.

Namespace: System.Data.SqlClient

Assembly: System.Data (in System.Data.dll)

Return Value Type: System.Data.SqlClient.SqlDataReader

ExecuteScalar Method:

Execute the command and return a single value. On many occasions, it is necessary to return a single result from a SQL statement, such as the count of records in a given table, or the current data time of the server.

Namespace: System.Data.SqlClient

Assembly: System.Data (in System.Data.dll)

Return Value Type: System.Object


Don't want to miss updates? Please click the below button!

Follow MindStick