Top 30 ADO.NET Interview Questions and Answers

Top 30 ADO.NET Interview Questions and Answers

Top 30 ADO.NET Interview Questions and Answers
Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

Introduction

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.



1) What is ADO.NET?

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.

2) What are the namespaces used in ADO.NET for data access?

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

3) What is the major difference between classic ADO and ADO.NET?
# 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.
4) Explain Ado.Net Architecture?

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:


  • Connection: Connection object is used to establish a connection between the application and the data source such as SQL Server, ORACLE, ACCESS etc.
  • Command: Command object is used to execute stored procedure and command on Database.
  • Data Adapter: This acts as a bridge between the database and a dataset.
  • Data Reader: this object reads data from the data store in forward only mode.
  • DataSet: DataSet object 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.


5) What are the two fundamental objects in ADO.NET

DataSet and DataReader are the 2 fundamental objects in ADO.NET.

6) What is the difference between DataReader & DataSet?
# 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.
7) What is the use of the Connection object in ADO.NET?

Connection object is used to establish a connection between application & the data source such as MS SQL SERVER, ORACLE, MS ACCESS etc.

8) What is the use of Command object?

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:

  1. ExecuteReader(): Used to execute the command which return a typed IDataReader.
  2. ExecuteNonQuery(): Used to execute the command which did not return any output.
  3. ExecuteScalar(): Used to execute the commands which return a single value.
  4. ExecuteXmlReader(): Used to execute the command that returns an XmlReader object.
9) What is the use of a Data Adapter?

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:

  1. Fill (): The Fill method populates a data table or a dataset object with data from the database. It retrieves rows from the data source(SQL Server, Oracle) using the SELECT statement specified by an associated select command property.
  2. FillSchema(): The FillSchema method Uses the SelectCommand to extract just the schema for a table from the data source, and creates an empty table in the DataSet object with all the corresponding constraints.
10) What is a DataSet object?

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.

     

     


« 1 2 3 »  

Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer & technology lovers. http://www.techstudy.org/.