ADO.NET - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

ADO.Net SqlCommand

ADO.Net SqlCommand

shape Description

Command object is used to perform the operations on the databse objects.
  • Here, Operations means insert, update, delete, alter, drop..etc.
  • database objects means tables, stored procedures, views..etc.
  • If we working with the DataReader then the Command object will work with the connected oriented architecture.
  • If we working with the DataAdapter then the Command object will work with the Disconnected oriented architecture.

shape Properties

The following are the properties of the command object.
  • CommandText
  • CommandType
  • CommandTimeout
  • Connection
  • Parameters
  • Transaction

Execution Methods of Command Object

shape Conceptual figure

The following diagram shows you the types of execution methods.

Steps to work with the Command Object

shape Description

Follow the below steps to work with the command object. Step 1: Declare the Command Object.

shape Syntax

[csharp]ClassName ObjectName;[/csharp]

shape Examples

[csharp]SqlCommand cmd;[/csharp] Step 2: Define the Command Object.

shape Syntax

[csharp]ObjectName = new ClassName(string CommandText,Conection)[/csharp]

shape Examples

[csharp]cmd = new SqlCommand("delete empdetails where eid=101",con)[/csharp] Step 3: Mention the CommandType.

shape Syntax

[csharp]ObjectName.CommandType = CommandType.Value;[/csharp]

shape Examples

[csharp]cmd.CommandType = CommandType.Text;[/csharp] Step 4: Execute the Command Object.

shape Syntax

[csharp]ObjectName.Executemethod();[/csharp]

shape Examples

[csharp]cmd.ExecuteNonQuery();[/csharp]