---
title: "Explain the use of Command objects?"  
description: "Explain the use of Command objects?"  
author: "Sunil Singh"  
published: 2017-06-30  
updated: 2020-09-24  
canonical: https://www.mindstick.com/interview/23273/explain-the-use-of-command-objects  
category: "c#"  
tags: ["ado.net", "asp.net"]  
reading_time: 2 minutes  

---

# Explain the use of Command objects?

Command objects are used to connect a Connection object to a DataReader or DataSet. Following are the methods provided by a Command object:

**ExecuteNonQuery**

It executes the command that defined in the command text that defined in the connection property for a query that does not return any row (an UPDATE, DELETE, or INSERT).After executing it Returns an Integer indicating the number of rows affected by the query.

**ExecuteReader**

It executes the command that defined in the command text that defined in the connection property. It Returns a "reader" object that is connected to the resulting row set within the database, allowing the rows to be retrieved.

**ExecuteScalar**

It executes the command that defined in the command text that defined in the connection property

After executing it Returns only a single value (effectively the first column of the first row of the resulting row set, any other returned columns and rows are discarded). It is fast and efficient when only a "singleton" value is required.

## Answers

### Answer by Sunil Singh

Command objects are used to connect a Connection object to a DataReader or DataSet. Following are the methods provided by a Command object:

**ExecuteNonQuery**

It executes the command that defined in the command text that defined in the connection property for a query that does not return any row (an UPDATE, DELETE, or INSERT).After executing it Returns an Integer indicating the number of rows affected by the query.

**ExecuteReader**

It executes the command that defined in the command text that defined in the connection property. It Returns a "reader" object that is connected to the resulting row set within the database, allowing the rows to be retrieved.

**ExecuteScalar**

It executes the command that defined in the command text that defined in the connection property

After executing it Returns only a single value (effectively the first column of the first row of the resulting row set, any other returned columns and rows are discarded). It is fast and efficient when only a "singleton" value is required.


---

Original Source: https://www.mindstick.com/interview/23273/explain-the-use-of-command-objects

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
