ADO.Net is a data accessing technology of the Microsoft .net framework. It communicates with DBMS and RDBMS both through a common set of components. It acts as a bridge between front-end control and back-end database. Objects of ado.net are responsible for all data-related operations. ADO.Net perform its functions in both Connected and Disconnected environments.
There are 2 main components of ADO.Net:
- Data Providers
System.Data namespace contain all the classes of ado.net.
Data Provider provides functionality to connect with databases. Data providers are used to performing operations on databases. Ado.net mainly work with 3 data providers in the .Net framework: Microsoft SQL Server data provider that uses sSqlConnection, an OLEDB data provider that uses OleDbConnection, an ODBC data provider that uses OdbcConnection.
A Data Provider contains objects of Connection, Command, DataAdapter and DataReader to perform the functionalities of the data provider.
- Connection: The object of Connection is used to establish a physical connection with the database. Connection String is used to providing necessary information for establishment of proper connection with the database.
sqlConnection con= new sqlConnection();
con.ConnectionString= “DataSource=msa-technosoft-pc; initial catalogue= msa-technosoft-db; user id= user1; password= pass1”;
- Command: The object of Command is used to execute SQL operations on databases. Command object provides several execute methods to perform SQL operations in different ways.
sqlCommand cmd= new sqlCommand(“insert into msa-tech-blog values(@slno, @title, @details)” ,con);
cmd.Parameters.AddWithValue(“@slno” , int.Parse(txtSlNo.Text));
cmd.Parameters.AddWithValue(“@title” , txtTitle.Text);
cmd.Parameters.AddWithValue(“@details” , txtDetails.Text);
- DataReader: This is an alternative of DataSet and DataAdapter. It is used in the connected environment. The object of DataReader allows direct access to the data records of databases.
- DataAdapter: It acts as a mediator between the database and DataSet object. It helps the DataSet to copy data from different data providers. It is useful in the disconnected environment.
The dataset is a subset of the database. It provides different mechanisms for data management in the disconnected environment. It is completely independent of the original data source. It is a copy of data source, but not having a physical connection with it. Reconnection is required to update the original database. It contains DataRelation, DataTable collection. The DataTable Collection is a collection of DataTable, DataRow, DataColumn, attribute and data.
- DataRelation: It is used to create a relation between two tables.
- DataTable: this class is used to represent the tables of the data source.
- DataRow: This object is used to represent a row of a table in Data Source.
- DataColumn: This is used to represent the column of a table in the data source.