In this article, you will find basic to most puzzled interview questions. This article is very useful for those who are preparing for an interview in IT company. Whether you are experienced or fresher, this article will cover all ADO.NET questions from basic to advanced level.
ADO.Net is usually termed as "ActiveX Data Objects" which is a part of .Net Framework. The ADO.NET framework has set of classes which are used to handle data access by connecting to different databases like MS SQL Server, MS Access, Oracle, SQL etc.
System.Data – This contains basic objects used for accessing and storing relational data such as Dataset, Datatable, Data Relation.
System.Data.SqlClient – This contains the object that we use to connect to a data source via SQL provider such as SqlConnection, SqlCommand etc.
System.Data.OleDb - This contains the object that we use to connect to a data source via OleBb provider such as OleDb Connection, OleDbCommand etc.
System.Data.SqlTypes - This Contains SQL Server data types System.Data.Common – Contains classes which are shared/overridden by data providers
# | ADO | ADO.Net |
---|---|---|
1. | ADO have recordset. | ADO.Net have Data Adapter and Dataset. |
2. | ADO objects communicate in binary mode. | ADO.NET uses XML for passing the data. |
3. | Since ADO derives information about data implicitly at runtime based on metadata, it is an expensive process. | By leveraging known metadata at design time, ADO.Net provide better runtime performance and more consistent runtime behavior |
4. | ADO supports mostly connection oriented models. | ADO.Net works in Disconnected manner. |
5. | Only Client Side Cursors are allowed in ADO. | ADO.Net Support both client side and server side cursors. |
The most important section in ADO.NET architecture is “Data Provider”. Data Provider provides access to the data source such as MS SQL Server, ORACLE, MS ACCESS etc. In short, it provides the object to achieve functionalities like opening and closing connection, retrieves data, and update data.
Here are main sections of a data provider:
DataSet and DataReader are the 2 fundamental objects in ADO.NET.
# | DataReader | DataSet |
---|---|---|
1. | DataReader Used in a connected architecture. | DataSet Used in a disconnected architecture. |
2. | ADO objects communicate in binary mode. | ADO.NET uses XML for passing the data. |
3. | Since ADO derives information about data implicitly at runtime based on metadata, it is an expensive process. | By leveraging known metadata at design time, ADO.Net provide better runtime performance and more consistent runtime behavior |
4. | ADO supports mostly connection oriented models. | ADO.Net works in Disconnected manner. |
5. | Only Client Side Cursors are allowed in ADO. | ADO.Net Support both client side and server side cursors. |
Connection object is used to establish a connection between application & the data source such as MS SQL SERVER, ORACLE, MS ACCESS etc.
Command object in ADO.NET is used to execute stored procedure and command on Database. This object mainly used to query the database and it can be of different types – Insert, Select, Modify and Delete.
1 2 3 4 5 6 7 |
//example string Connection = "server=localhost; uid = techstudy-pc; password=myPass; database = SampleDB"; SqlConnection con = new SqlConnection(Connection); con.Open(); string select = "Select * from tblstudent"; SqlCommand cmd = new SqlCommand(select, con); con.Close(); |
Following are the methods provided by a Command object:
The DataAdapter in ADO.NET is used to bridges the gap between the disconnected DataTable objects and the physical data source. The SqlDataAdapter is capable of executing an UPDATE, SELECT & DELETE statement on a data source such as SQL Server, MS Access etc.
1 2 3 4 5 6 7 8 9 |
//example string Connection = "server=localhost; uid=techstudy-pc; password=myPass; database = SampleDB"; SqlConnection con = new SqlConnection(Connection); con.Open(); string StrSql = "Select * from tblstudent"; SqlDataAdapter Adapter = new SqlDataAdapter(); Adapter.SelectCommand = new SqlCommand(StrSql, con); DataSet ds = new DataSet("students"); Adapter.Fill(ds); |
A Data Adapter mainly supports following two methods:
DataSet object in ADO.NET represents disconnected and cached data. If you see the diagram, it is not in direct connection with the data store (MS SQL Server, MS Access, Oracle, etc.) rather it talks with the data adapter, who is responsible for filling the dataset. The dataset can have one or more datatables and relations.
The DataSet class exists in the System.Data namespace.
11 January 2019 2383 Written By: Rohit
© 2020 Tech Study. All rights reserved | Developed by Tech Study| Privacy Policy | Sitemap