Command objects uses, purposes and their methods.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:
1) Execute : Executes the queries, stored procedures etc. 2) Cancel : Stops the method execution. 3) CreateParameter : To create a parameter object.
|