• +91 9723535972
  • info@interviewmaterial.com

Ado.net Interview Questions and Answers

Ado.net Interview Questions and Answers

Question - 31 : - What is a DataAdapter in ADO.NET?

Answer - 31 : -

  • A DataAdapter is used to access data from a data source by functioning as a bridge between DataSet and a data source. DataAdapter class includes an SQL command set and a database connection. It is helpful to fill the DataSet and resolve changes to the data source.
  • The DataAdapter will make use of the Connection object that belongs to the .NET Framework data provider for connecting with a data source. Along with that, it will also use Command objects to retrieve data from the data source as well as to resolve changes to the data source.
  • DataAdapter properties that permit the user to control the database are the Select command, Update command, Insert command, and Delete command.
  • Example code for the usage of DataAdapter:
using System;  
using System.Data.SqlClient;  
using System.Data;  
namespace DataAdapterExample  
{  
    public partial class DataAdapterDemo : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            using (SqlConnection conn = new SqlConnection("data source=.; database=items; integrated security=SSPI"))  
            {  
                SqlDataAdapter da = new SqlDataAdapter("Select * from items", conn);  
                DataSet s = new DataSet();  
                da.Fill(s);  
                GridView1.DataSource = s;  
                GridView1.DataBind();  
            }  
        }  
    }  
}  
Here, DataAdapter will receive the data from the items table and fill the DataSet, which will be later used to display the information retrieved from the items database.

Question - 32 : - Explain the difference between ADO.NET and ASP.NET.

Answer - 32 : -

ADO.NET(ActiveX Data Objects)

ASP.NET(Active Server Pages)

ADO.NET is a Library within the .NET framework.

ASP.NET is a Framework.

It is a technology useful for accessing data from databases.

It is a technology useful for the creation of dynamic web pages.

Here, data can be converted into XML format.

Here, We can write our code into VB.Net, C#, ASP.Net, etc.

It is used to develop reliable and scalable database applications with high performance for client-server applications.

It is used to create dynamic web pages, web applications, websites, and web services.

Question - 33 : - Explain about DataSet types in ADO.NET.

Answer - 33 : -

DataSet can be said as a collection of database tables(row and column format) that holds the data. There are two types of DataSet in ADO.NET. They are:

  • Typed DataSet: A typed DataSet is derived from the DataSet base class and can be created by selecting the DataSet option provided by Visual Studio. It will be created as an XML schema(.xsd file) that contains DataSet structure information such as rows, columns, and tables. Data from the database is moved into a dataset and from the dataset to another component in the XML format.
  • Untyped DataSet: Untyped DataSet does not have an associated XML schema with it. Users are supposed to add columns, tables, and other elements to it. Properties can be set during design time or can add them during run time.
Example program for the usage of DataSet:

using System;  
using System.Data.SqlClient;  
using System.Data;  
namespace DataSetDemo  
{  
    public partial class DataSetExample : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            using (SqlConnection conn = new SqlConnection("data source=.; database=employee; integrated security=SSPI"))  
            {  
                SqlDataAdapter da = new SqlDataAdapter("Select * from employee", conn);  
                DataSet d = new DataSet();  
                da.Fill(d);  
                GridView1.DataSource = d;  
                GridView1.DataBind();  
            }  
        }  
    }  
}  
Here, DataSet will be filled by DataAdapter that receives data from the employee table. This DataSet will be used to display the information received from the employee database.

Question - 34 : - Explain the difference between DataTable and DataSet.

Answer - 34 : -

DataTable

DataSet

DataTable consists of a single database table that is placed within a memory.

DataSet consists of a collection of multiple database tables which is placed within a memory.

It has a row and column collection.

It has a database table collection.

It allows fetching only a single TableRow at a time.

It allows fetching multiple TableRows at a time.

It is a single database table, so there will not be any relation with other tables.

It represents a collection of DataTable objects, so there might be a relation between them to obtain a particular result.

In this, DataSource objects are not serialized.

In this, DataSource objects are serialized.

UniqueConstraint and ForeignKeyConstraint objects are not available enforcing data integrity.

UniqueConstraint and ForeignKeyConstraint objects are available for enforcing data integrity.

Question - 35 : - What are the different namespaces available in ADO.NET?

Answer - 35 : -

Various namespaces available under ADO.NET is given below:

  • System.Data: It contains the definition for rows, columns, relations, views, tables, constraints, and databases.
  • System.Data.SqlClient: It is a collection of classes that are helpful in connecting to a Microsoft SQL Server database such as SqlConnection, SqlCommand, SqlDataAdapter, etc.
  • System.Data.Odbc: It consists of classes that are required for connecting with most Odbc Drivers. These classes include OdbcConnection, OdbcCommand.
  • System.Data.OracleClient: It has classes required for connection with an Oracle database, OracleConnection, OracleCommand.

Question - 36 : - What is object pooling?

Answer - 36 : -

Object pooling is a repository of the objects in memory that can be reused later without creating them. This object pooling reduces the burden of creating objects when it is required. Whenever there is a requirement of an object, the object pool manager will process the request and serve accordingly. It is designed for optimizing the use of limited resources so that the demands of client requests will be fulfilled.

Question - 37 : - Differentiate DataSet and DataReader.

Answer - 37 : -

DataSet

DataReader

DataSet provides read/write access to data, so we can update the data.

DataReader provides read-only access to data, so we can’t update the data.

It has a disconnected architecture, which means the data obtained from the database can be accessed even after the database connection was closed.

It has a connected architecture, which means to access the data retrieved from the database, the connection must be opened.

It supports various database tables from different databases.

It supports only a single table from a single database.

It provides slower access to data due to overhead.

It provides faster access to data.

Both forward and backward scanning of data is possible.

Only forward scanning of data is possible.

Question - 38 : - What are the different execute() methods available in ADO.NET?

Answer - 38 : -

Different execute() methods supported by SqlCommandObject in ADO.NET is given below:

  • ExecuteScalar(): This method returns only a single value from the first row and first column of the ResultSet after the execution of the query. Even if ResultSet is having more than one row or column, all those rows and columns will be ignored. If the ResultSet is empty, it will return NULL.
  • ExecuteNonQuery(): This method returns the number of rows affected by the execution of a query. This method is not useful to return the ResultSet.
  • ExecuteReader(): This method returns an object of DataReader which is a read-only and forward-only ResultSet. It needs a live connection with the Data Source. We cannot directly instantiate the DataReader object. A valid DataReader object can be created with the help of the ExecuteReader() method.
  • ExecuteXmlReader(): This method builds an object of the XmlReader class and will return the ResultSet in the form of an XML document. This method is made available in SQL Server 2000 or later.

Question - 39 : - What is a transaction in ADO.NET? Explain the types of transactions available in ADO.NET.

Answer - 39 : -

In ADO.NET, transactions are used when you want to bind several tasks together and execute them in the form of a single unit. The transaction provides data consistency by ensuring either all of the database operations will be succeeded or all of them will be failed. For example, consider an application that performs two tasks. First, it updates an item_order table with order information. Second, it updates an item_inventory table that holds inventory information, where a number of items ordered will be debited. If any one of the tasks fails, then both updates must be rolled back.

Two types of transactions supported by ADO.NET are as follows:

Local Transaction:
  • A local transaction is a single-phase transaction that is directly handled by the database. Every .NET Framework data provider has its own Transaction object for bringing out local transactions.
  • For example, if we want to perform a transaction using SQL Server database, we import a System.Data.SqlClient namespace. Similarly, to perform an Oracle transaction, import the System.Data.OracleClient namespace. A DbTransaction class will be used for writing code that is independent of the provider and that requires transactions.
Distributed Transaction:
  • A distributed transaction is coordinated by a transaction monitor and will make use of fail-safe mechanisms like two-phase commit for transaction resolution. This transaction will affect multiple resources.
  • If the user can make use of a distributed transaction, if he wants to do a transaction across multiple data servers such as Oracle, SQL Server, etc.
  • If you want a distributed transaction to commit, all participants must guarantee that data modification made will be permanent. Changes must remain unchanged even if the system crash or other unforeseen events occur. Even if a single participant will make this guarantee fail, then the entire transaction will fail, and updates made to data within the transaction scope are rolled back.

Question - 40 : - What is data binding in ADO.NET?

Answer - 40 : -

  • Data binding in ADO.NET is the process through which user interface (UI) controls of a client application are configured to update or fetch data from data sources like a database or XML document. Using data binding, the user will be able to bind values to the particular control.
There are two types of data binding based on the type of binding offered:
  1. Simple data binding: It is the process of binding the control with only one value in the dataset. The controls such as label, text box will be made bound to the control using the control properties.
  2. Complex data binding: It is the method of binding the component with the Database. The controls can be a Dropdown list, GridView, or combo box. One or more than one value can be displayed from the dataset using the complex data binding.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners