Tuesday, February 2, 2010

Components of data providers in ADO.NET

The Connection Object
The Connection object represents the connection to the database. The Connection object has ConnectionString property that contains all the information, required to connect to the database.
The Command Object
The command object is used to execute stored procedures and command on the database. It contains methods to execute command on the database such as ExecuteNonQuery, ExecuteScalar and ExecuteReader.
ExecuteNonQuery
Executes commands that return no records, such as INSERT, UPDATE, or DELETE
ExecuteScalar
Returns a single value from a database query
ExecuteReader
Returns a result set by way of a DataReader object

The DataReader Object
The DataReader object provides a connected, forward-only and read-only recordset from a database. The Command.ExecuteReader method creates and returns a DataReader object. Since it is connected to the database throughout its lifetime, it requires exclusive use of connection object.
The DataAdapter Object
The DataAdapter object acts a communication bridge between the database and a dataset. It fills the dataset with data from the database. The dataset stores the data in the memory and it allows changes. The DataAdapter's update method can transmit the changes to the database.
The DataAdapter Object's properties.
SelectCommand
Contains the command text or object that selects the data from the database.
InsertCommand
Contains the command text or object that inserts a row into a table.
DeleteCommand
Contains the command text or object that deletes a row from a table.
UpdateCommand
Contains the command text or object that updates the values of a database.

0 Comments: