Tuesday, April 3, 2012

ADO.NET's basic methods to run queries with SqlCommand

SqlClient namespace in ADO.NET provides 3 basic methods to run queries with SqlCommand against MSSQL:

ExecuteReader: When database query is going to provide a set of records.

ExecuteNonQuery: 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

ExecuteScalar: When database query returns a single value and this value cannot be defined as output parameter, because of T-SQL type limitation for variables. For example type image cannot be output parameter in MSSQL.

About Us