Sunday, 6 May 2012

What is the difference between ExecuteNonQuery(), ExecuteReader() and ExecuteScalar() methods in ADO.NET || Comparision among Executtion Methods of Command Class


ExecuteNonQuery():
1.will work with Action Queries only (Create,Alter,Drop,Insert,Update,Delete).
2.Retruns the count of rows effected by the Query.
3.Return type is int
4.Return value is optional and can be assigned to an integer variable.

ExecuterReader():
1.will work with Action and Non-Action Queries (Select)
2.Returns the collection of rows selected by the Query.
3.Return type is DataReader.
4.Return value is compulsory and should be assigned to an another object DataReader.

ExecuteScalar():
1.will work with Non-Action Queries that contain aggregate functions.
2.Return the first row and first column value of the query result.
3.Return type is object.
4.Return value is compulsory and should be assingned to a variable of required type.



2 comments:

  1. sir, what is the difference in between connected and disconnected architecture and when to use them ?
    Thanks in advance

    ReplyDelete
    Replies
    1. --- Connected Oriented ---
      1. Make connection , Keep connection to do operation , close connection when it get called.
      2. contains Data Reader
      3. uses Data Table ( single table in DB)

      -- Disconnected ---
      1. Make connection, Fetch data one time, Close connection ( fetch data uses to access database even the connection is closed, done by using relationship between tables)
      2. Contains DataAdapter ( bridge between data base and sqlcommand qry)
      3. Uses Dataset ( collection of data tables)

      Delete