110 likes | 120 Views
ADO.NET. Evolution of ADO.NET DAO RDO ADO Connected Connection Problems with connected connection Why ADO.NET? Disconnected Connection. ADO.NET Data Architecture. Two components: DataSet and Data Provider. DataSet. disconnected, in-memory representation of data
E N D
ADO.NET • Evolution of ADO.NET • DAO • RDO • ADO • Connected Connection • Problems with connected connection • Why ADO.NET? • Disconnected Connection
Two components: • DataSet and Data Provider
DataSet • disconnected, in-memory representation of data • local copy of the relevant portions of the DB • persisted in memory independent of DB • Supports SQL Server, Oracle, MS-Access, etc..
Data Provider • providing and maintaining the connection to DB • set of related components • two DataProviders: • SQL Data Provider • OleDb DataProvider • Each DataProvider consists of the following component classes:
The Connection object which provides a connection to the database • The Command object which is used to execute a command • The DataReader object which provides a forward-only, read only, connected recordset • The DataAdapter object which populates a disconnected DataSet with data and performs update
The Connection Object • SqlConnection • OleDbConnection
The Command Object • SqlCommand • OleDbCommand • used to execute: • Commands, • Stored Procedures, • SQL Command, • or return complete tables directly • provide three methods: • ExecuteNonQuery: INSERT, UPDATE or DELETE • ExecuteScalar: Returns a single value • ExecuteReader: Returns a result set by way of a DataReader object
The DataReader Object • provides a forward-only, read-only, connected stream recordset • cannot be directly instantiated • returned as the result of the Command object's ExecuteReader method • SqlCommand.ExecuteReader method returns a SqlDataReader object, • OleDbCommand.ExecuteReader method returns an OleDbDataReader object • only one row is in memory at a time- Lowest overhead.
The DataAdapter Object • the core of ADO .NET's disconnected data access • Middleman between the DB and a DataSet • fill a DataTable or DataSet with data from the database with it's Fill method • DataAdapter can commit the changes to the database by the Update method • provides four properties: • SelectCommand • InsertCommand • DeleteCommand • UpdateCommand