In order to interact with any database we need a Connection . This connection enables us to know the Server Name, User-Id,Password,Database Name. These are the main requirements to connect to a Database.
So in our Connection string we provide all those above mentioned properties as parameters.
Different Connection objects : SqlConnection, OleDbConnection, OdbcConnection
. OleDbConnection object is used with an OLE-Db Provider
OleDbConnection cnn ; connetionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=DatabaseName;"; cnn = new OleDbConnection(connetionString);
. SqlConnection object used the Tabular Data Services (TDS) With MS Sql Server.
SqlConnection con; con = new SqlConnection("server=SERVER NAME;user id=ID;password=PASSWORD;database=DB NAME"); SqlCommand cmd; cmd = new SqlCommand("DB Query Here",con);
. Using the OdbcConnection , we will create an OdbcCommand. From that command we can issue a Query and create an OdbcDataReader.
OdbcConnection DbConnection = new OdbcConnection("Connection String"); OdbcCommand DbCommand = DbConnection.CreateCommand(); DbCommand.CommandText = "Db Query Here"; OdbcDataReader DbReader = DbCommand.ExecuteReader();
Data view is used to sort and find data in a data table.
These objects connect one or more Command objects to a Dataset object. They provide logic that would get data from the data store and populates the tables in the Dataset, or pushes the changes in the Dataset back into the data store.
Data reader and Dataset are the two fundamental objects in ADO.NET.
BENEFITS OF ADO.NET
ADO.NET works on DataSet that can represent a whole database or even a data table as a disconnected object and thereby eliminates the problem of the constraints of number of databases being connected. In this way scalability is achieved.
Data Source Independence
In ADO.NET DataSet is completely independent of data source and no way DataSet is controlled by the data source as it happens in case of RecordSet.
As ADO.NET transmits the data using the format of XML which is not dependent on ADO.NET or windows platform.
Strongly Typed Fields
It supports strongly typed fields by using CTS.
The performance in ADO.NET is higher in comparison to ADO that uses COM marshalling.
As in ADO.NET transmission is via XML format, therefore it can pass through firewalls.