Microsoft.NET

……………………………………………….Expertise in .NET Technologies

Command Objects in ADO.NET

Posted by Ravi Varma Thumati on September 21, 2009

The command objects are used to connect to the DataReader or DataSet objects with the help of the following methods:

ExecuteNonQuery:

  • This method executes the command defined in the CommandText property.
  • The connection used is defined in the Connection property for a query.
  • It returns an Integer indicating the number of rows affected by the query.

ExecuteReader:

  • This method executes the command defined in the CommandText property.
  • The connection used is defined in the Connection property.
  • It returns a reader object that is connected to the resulting rowset within the database, allowing the rows to be retrieved.

ExecuteScalar:

  • This method executes the command defined in the CommandText property.
  • The connection used is defined in the Connection property.
  • It returns a single value which is the first column of the first row of the resulting rowset.
  • The rows of the rest of the result are discarded.
  • It is fast and efficient in cases where a singleton value is required.

Command objects uses, purposes and their methods.

Command objects are used to execute the queries, procedures. Sql statements etc. It can execute stored procedures or queries that use parameters as well.

It works on the basis of certain properties like ActiveConnection, CommandText, CommandType, Name etc.

Command object has three methods:

a) Execute: executes the queries, stored procedures etc.
b) Cancel: stops the method execution
c) CreateParameter: to create a parameter object

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: