Ashish Kumar Singh
Explain the use of ExecuteNonQuery, ExecuteReader, ExecuteScalar?
By Ashish Kumar Singh in ASP.NET on Oct 01 2012
  • kiran kumar
    Feb, 2013 4

    These are the methods under Command Object ExecuteReader : Used to execute SQL Select Command ExecuteScalar : Used to execute SQL Select command which is used to return a single value. Example the group function output ExecuteNonQuery : USed to execute SQL Insert, Delete and Update Commands.

    • 2
  • Dipak V Nakum
    Mar, 2019 20

    ExecuteScalar is typically used when your query returns a single value. If it returns more, then the result is the first column of the first row. An example might be SELECT @@IDENTITY AS 'Identity'. ExecuteReader is used for any result set with multiple rows/columns (e.g., SELECT col1, col2 from sometable). ExecuteNonQuery is typically used for SQL statements without results (e.g., UPDATE, INSERT, etc.).

    • 0
  • Vithal Wadje
    Oct, 2012 5

    ExecuteScalar--ExecuteScalar returns only one value after execution of the query . it returns the first field in the first row. it is faster and convinient way when you wants rerive only single value at a time.

    • 0
  • Vithal Wadje
    Oct, 2012 5

    ExecuteReader-this method returns a DataReader which is filled with the data that is retrived using the coommand object . this is known as a forward only retrival of records.

    • 0
  • Vithal Wadje
    Oct, 2012 5

    ExecuteNonQuery- ExecuteNonQuery does not return any data at all. it is used basically to insert update operationas on table. means it is used for execution of DML commands e.g sqlcommand cmd=new sqlCommand("insert into emp values ('1','2'",con); con.open(); cmd.ExecuteNonquery();

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS