What are the Methods of Commands in ADO.NET ?
Naitik Jani
They are used to connect a Connection object to a DataReader or DataSet. Following are the methods provided by a Command object:ExecuteNonQuery: Executes the command defined in the CommandText property against the connection defined in the Connection property for a query that does not return any row (an UPDATE, DELETE, or INSERT). Returns an Integer indicating the number of rows affected by the query.ExecuteReader: Executes the command defined in the CommandText property against the connection defined in the Connection property. Returns a "reader" object that is connected to the resulting row set within the database, allowing the rows to be retrieved.ExecuteScalar: Executes the command defined in the CommandText property against the connection defined in the Connection property. 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.
SQL Command Class having three types of methods in ADO.Net==>1) ExecuteNonQuery(); [Integer return type] return number of effected rows by DML Statement.2) ExecuteReader(); [SQl DataReader return type] Holds n-number of rows collection till the connection state is open. 3) ExecuteScaler(); [object return type] return a single cells value from the result of 'Select' statement.
ExexuteNonQueryExecuteScalerExecuteReader
ExecuteNonQuery: This command method is used for other than select query. For inserting, updating and deleting.ExecuteScalar: This command method used to return single value of a first column record.ExecuteReader: This command method is used to read more than one records from a database.
ExecuteNonQuery ExecuteScalar ExecuteReader
ExecuteReder,ExecuteNonQuery,ExecuteScaler
ExecuteNonQuery ExecuteScalar, ExecuteReader
1)ExecuteNonQuery:-This method executes the command specifies and returns the number of rows affected 2)ExecuteScaler:-returns the first column of first row of the result set. 3) ExecuteReader:-return the set of rows
General methods of Command Class are ExecuteNonQuery(); ExecuteScalar(); ExecuteReader(); are the three main methods of Command class.
ExexuteNonQueryExecuteScalerExecuteReaderFill
ExecuteNonQuery ExecuteReader ExecuteScalar Cancel Clone GetType
Methods of commands in ADO.NET ExecuteNonQuery ExecuteReader ExecuteScalar
ExecuteNonQuery() : Doesn't return any data but returns affected row count. Return type is integer.ExecuteScalar Method(): It returns the value only in the first column of the first row. Return type is object. ExecuteReader(): It returns a DataReader object.ExecuteXMLReader(): It returns a XMLReader object.
The following are the most commonly used methods of the SqlCommand class. ExecuteReader - Use when the T-SQL statement returns more than a single value. For example, if the query returns rows of data. ExecuteNonQuery - Use when you want to perform an Insert, Update or Delete operation ExecuteScalar - Use when the query returns a single(scalar) value. For example, queries that return the total number of rows in a table.
Execute Non Query :-Executes the command defined in the command text property against the connection defined in the connection property for a query that does not return any row (Insert, Update or Delete).Returns an integer indicating the number of rows affected by the query. Execute Reader :- Executes the command defined in the command text property against the connection defined in the connection property.Returns a reader object that in connected to the resulting row set within the data base, allowing the rows to be retrieved. Execute Scalar :-Executes the command defined in the command text property against the column defined in the connection property.Returns only single value the first column of the first row of the resulting row set any other returned columns and rows are discarded.
ExecuteNonQuery() ExecuteScalar() ExecuteReader()
1.ExecuteNonQuery: This method executes the command specifies and returns the number of rows affected. 2.ExecuteReader: The ExecuteReader method executes the command specified and returns an instance of instance of SqlDataReader class. 3.ExecuteScalar: This method executes the command specified and returns the first column of first row of the result set. The remaining rows and column are ignored. 4.ExecuteXMLReader: This method executes the command specified and returns an instance of XmlReader class. This method can be used to return the result set in the form of an XML document
ExecuteReader : Returns a DataReader object. ExecuteScalar : Returns a single scalar value. ExecuteNonQuery : Executes a command that does not return any rows. ExecuteXMLReader : Returns an XmlReader. Available for a SqlCommand object only.
Hello Naitik,As per as Command object is concern i come up with Important properties and method listed below.Properies : 1) CommandText2) CommandType3) CommandTimeout4) Connection.5) DbConnection. Methods : 1) ExecuteNonQuery.2) ExecuteScalar.3) ExecuteReaderFor more information go to visual studio whatever version you have and take a reference of System.Data.SqlClient and create a object of SqlCommand object right client on class and select "Go to defination" or press F12 then you will find everything.
ExecuteNonQuery : Insert ,Update and DeleteExecuteScalar : Select (For Single Value return)ExecuteReader :Select
SQL Command Class having three methods in ADO.Net i.e.1)ExecuteNonQuery() [Integer return type] on DML Statement 2)ExecuteScaler() [Object return type] Use Select Command 3)ExecuteReader() [SQL Data Reader return type] Holdes n-number of rows collection till the connection satae is open
ExecuteNonQueryExecuteScalarExecuteReader
The Command Object in ADO.NET executes SQL statements and Stored Procedures against the data source specified in the C# Connection Object. The Command Object requires an instance of a C# Connection Object for executing the SQL statements .In order to retrieve a resultset or execute an SQL statement against a Data Source , first you have to create a Connection Object and open a connection to the Data Source specified in the connection string. Next step is to assign the open connection to the connection property of the Command Object . Then the Command Object can execute the SQL statements. After the execution of the SQl statement, the Command Object will return a result set . We can retrieve the result set using a Data Reader .
-> ExecuteNonQuery-> ExecuteScalar-> ExecuteReader
ExecuteNonQuery ExecuteReader ExecuteScalar
http://dotnet-munesh.blogspot.in/2013/12/adonet.html