What are the methods provided by Command Objects in ADO.NET?Once when
the connection is established, command object is used to define and execute
a query.
Command object contains different methods for executing a query. These methods are listed below: ExecuteNonQuery:
When you frame any UPDATE query or DELETE query or INSERT query, you can
use ExecuteNonQuery method to execute them. This method will return an
integer value indicating how many records in the table have been affected
because of the query. Its syntax will be: ExecuteReader:
When you frame any SELECT queries, you might want the result set during
execution. This result set is returned by ExecuteReader method which actually
returns a reader object which when iterated gives the rows and columns
of the result. Its syntax is mentioned below: ExecuteScalar:
This method can also be used to execute SELECT queries but only a single
value will be returned as a result. Even if your query result contains
multiple rows and columns, only the first rows first column will
be displayed. If your query is going to return a single value then it
is advantageous to use ExecuteScalar method since there is no need for
reader object and record iterations. Its syntax is as shown: ExecuteXMLReader:
This method is similar to ExecuteReader. But it executes the SELECT query
and returns XMLReader object instead of a datareader. This XMLReader object
can then be traversed to display the result of the query. Its syntax is
shown below:
|