ADO.NET interview Questions


1. What is ADO.Net? Why Ado.net?
answer: ADO.NET :- 
It is an integral component in .NET framework, which was introduced by the Microsoft with .NET Framework 1.0
 2. It is a Data Access Object, which allows communication between .NET application and Databases.
WHY: 1. whenever .NET application wants to communicate Databases it has to take the help of Ado.Net.
2. Ado.net acts like a mediator between .Net application and Database.    
  <hr/>
2. Difference between Connected Oriented Architecture (COA) and Disconnected Oriented Architecture (DOA)? ,
answer: Connected Oriented Architecture (COA)
1. Whenever we require a continuous  connection with the Database for accessing the data we use COA
2. In COA, SqlDataReader will fetch the data from database and bind to the Client application.
Disconnected Oriented Architecture (DOA):-
1. Whenever we doesn’t require acontinuous connection with the Database for accessing the data we can  use DOA.
2. In DOA, SqlDataAdapter will fetch the data from database and store into  the DATASET in the Client  application.
<hr/>
3 .What is the base class library used for ado.net?
answer:-
System.data To communicate Sql server database we have to import a Base Class Library called 
Using System.Data.SqlClient
    <hr/>
4. What are components required for connected oriented?
answer:
The components required for Connected oriented architecture are:
1. Connection Object
2. Command Object  
3. DataReader Object  
    <hr/>
5. What are the components required for Disconnected oriented?
answer:
The components required for Disconnected oriented architecture are:  
1. Connection Object  
2. Command Object  
3. DataAdapter Object  
4. Dataset Object 
    <hr/>
6 . What are the two fundamental objects in ADO.NET? 
answer:
There are two fundamental objects in ADO.NET.
Datareader - connected architecture and
Dataset - disconnected architecture.  
<hr/>

7. What are the data access namespaces in .NET?,
answer: \nThe most common data access namespaces :\nSystem.Data\nSystem.Data.OleDb\nSystem.Data.SQLClient\nSystem.Data.SQLTypes\nSystem.Data.XML\nSystem.Data.LINQ  
    <hr/>

    8,
      What are major difference between classic ADO and ADO.NET?,
      answer:In ADO the in-memory representation of data is the recordset.A Recordset object is used to hold a set of records from a database table.\nIn ADO.NET we have dataset.A DataSet is an in memory representation of data loaded from any data source.
    <hr/>
    9,
      What is the use of connection object in ado.net? ,

      answer:The ADO Connection Object is used to create an open connection to a data source. Through this connection, you can access and manipulate a database.
    <hr/>

    10,
      What are the benefits of ADO.NET?,
      answer:\nScalability\nData Source Independence\nInteroperability\nStrongly Typed Fields\nPerformance
    <hr/>

    11,
      What are the parts of ADO.NET?,

      answer:ADO.NET is divided into the Dataset object for manipulating disconnected data and the .NET Data Providers for communicating with backend data stores and the Dataset.
    <hr/>

    12,
       Whate are different types of Commands available with DataAdapter ?,
      answer:The SqlDataAdapter has\nSelectCommand\nInsertCommand\nDeleteCommand\nUpdateCommand
    <hr/>
    13,
      What is the difference between an ADO.NET Dataset and an ADO Recordset?,
      answer: Dataset can fetch source data from many tables at a time, for Recordset you can achieve the same only using the SQL joins.\nA DataSet can represent an entire relational database in memory, complete with tables, relations, and views, A Recordset can not.\nA DataSet is designed to work without any continues connection to the original data source; Recordset maintains continues connection with the original data source.\nDataSets have no current record pointer, you can use For Each loops to move through the data. Recordsets have pointers to move through them.
    <hr/>

    14,
      What are the parameters that control most of connection pooling behaviors?,
      answer: Connect Timeout\nMax Pool Size\nMin Pool Size\nPooling
    <hr/>

    15,
        What is a DataSet? ,
      answer:A DataSet is an in memory representation of data loaded from any data source. 
    <hr/>

    16,
       What is a DataTable? ,
      answer:A DataTable is a class in .NET Framework and in simple words a DataTable object represents a table from a database.  
    <hr/>

    17,
      What is the data provider name to connect to Access database?,
      answer: Microsoft.Access 
    <hr/>
    18,
       Which namespaces are used for data access? ,
      answer:System.Data\nSystem.Data.OleDB\nSystem.Data.SQLClient 
    <hr/>

    19,
      What is difference between dataset and datareader? ,
      answer:DataReader provides forward-only and read-only access to data, while the DataSet object can hold more than one table (in other words more than one rowset) from the same data source as well as the relationships between them.\nDataset is a disconnected architecture while datareader is connected architecture.\nDataset can persist contents while datareader can not persist contents, they are forward only.  
    <hr/>

    20,
      What are the major components of data provider?,
      answer:The Connection object which provides a connection to the database.\nThe Command object which is used to execute a command.\nThe DataReader object which provides a forward–only, read only, connected recordset.\nThe DataAdapter object which populates a disconnected DataSet with data and performs update. 
    <hr/>
    21,
      What is Dataset?,
      answer: A Dataset is a container where all the rows fetched from a database table.\nIt is the job of DataAdapter to fill the Dataset with rows from the database.  
    <hr/>
    22,
      What are the advantage of ADO.Net? ,
      answer: Database Interactions Are Performed Using Data Commands\nData Can Be Cached in Datasets\nDatasets Are Independent of Data Sources\nData Is Persisted as XML.  
    <hr/>

    23,
      What is DataAdapter?,
      answer:DataSet contains the data from the DataAdapter which is the bridge between the DataSet and Database. DataAdapter provides the way to retrieve and save data between the DataSet and Database. It accomplishes this by means of request to the SQL Commands made against the database.
    <hr/>24,
       Name some ADO.NET Objects?  ,
      answer:\nConnection Object\nDataReader Object\nCommand Object\nDataSet Object\nDataAdapter Object
    <hr/>25,
      What is the DataTableCollection?  ,
      answer:An ADO.NET DataSet contains a collection of zero or more tables represented by DataTable objects. The DataTableCollection contains all the DataTable objects in a DataSet.
    <hr/>26,
      What is the parent class for all asp.net web server controls?,
      answer:System.Web.UI.Control.
    <hr/>27,
       How many types of memories are there in .net?,
      answer:Two types of memories are there in.net.  1. Stack memory and  2. Heap memory
    <hr/>28,
      How to create  a SqlConnection Object?  ,
      answer: SqlConnection con = new SqlConnection(Data Source=.;Initial Catalog=msdb;Integrated Security=True ); 
    <hr/>29,
      How to creating a SqlCommand Object?,
      answer:It takes a string parameter that holds the command you want to execute and a reference to a SqlConnection object.\nSqlCommand cmd = new SqlCommand(select CategoryName from Categories, con);
    <hr/>30,
       How to load multiple tables into dataset? ,
      answer:SqlDataAdapter da = new SqlDataAdapter(Select * from Id; Select * from Salry , mycon);\nda.Fill(ds);\nds.Tables[0].TableName = Id;\nds.Tables[1].TableName = Salary;
    <hr/>31,
      What is the difference between SqlCommand and SqlCommandBuilder?  ,
      answer:SQLCommand is used to retrieve or update the data from database.\nSQLCommandBuilder object is used to build & execute SQL (DML) queries like select insert update& delete.
    <hr/>32,
       What is the use of SqlCommandBuilder?,
      answer:SQL CommandBuilder object is used to build & execute SQL (DML) queries like select insert update& delete.  
    <hr/>33,
      How to copy the database from one server to another server?,
      answer:The easiest way to copy a database from one server to another is to back up the database from the source server in the form of SQL script and execute the SQL script on the destination server to recreate database and its respective tables.   
    <hr/>34,
       What is LINQ?,
      answer:LINQ is an acronym for the Language Integrated Query and is a part of .NET framework.\nIt defines a set of Standard Query Operators that enables us to query data in .NET supported languages.   
    <hr/>35,
      Explain ADO.Net Architecture?,
      answer:ADO.NET provides the efficient way to manipulate the database. It contains the following major components. 1. DataSet Object 2. Data Providers :\nConnection Object\nCommand Object\nDataReader Object\nDataAdapter Object.
    <hr/>36,
       What is the role of the DataReader class in ADO.NET connections?,
      answer:It returns a read-only, forward-only rowset from the data source. A DataReader provides fast access when a forward-only sequential read is needed.
    <hr/>37,
      What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?,
      answer:\nSQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix. OLE-DB.NET is a .NET layer on top of the OLE layer, so it’s not as fastest and efficient as SqlServer.NET
    <hr/>38,
       What are the config files we have in asp.net?,
      answer:In ASP.NET we have 2 types of Configuration files. They are- 1. Web.Config and 2. Machine.config
    <hr/>39,
       What is web.config file? How many web.cofig can contain a single application?  ,
      answer:\n1. Web.Config is one of the configuration files.  2. It is a XML file. 3. This file we can use to define the ASP.NET application configuration settings.  We can have MULTIPLE Web.Config files within a single application.
    <hr/>40,
       What is DataRowCollection? ,
      answer:\nSimilar to DataTableCollection, to represent each row in each Table we have DataRowCollection.
    <hr/>41,
       What are basic methods of Dataadapter? ,
      answer:\nFill\nFillSchema\nUpdate
    <hr/>42,
       What are the various methods provided by the dataset object to generate XML? ,
      answer:ReadXML : Read’s a XML document in to Dataset.\nGetXML : This is a function which returns the string containing XML document.\nWriteXML : This writes a XML data to disk.
    <hr/>43,
       What is DataSet Object?·,
      answer: Dataset is a disconnected, in-memory representation of data. It can contain multiple data table from different database.
    <hr/>44,
      What is the role of DataReader object?,
      answer: A DataReader object provides forward only, read only access to a database.\nThe connection to the database must be open while accessing data through DataReader object.\nIt loads only a single row at a time in the memory.
    <hr/>45,
      Which architecture does datasets follow? ,
      answer:Datasets follows the disconnected data architecture.
    <hr/>46,
      What is Serialization?,
      answer:Serialization is the process of persisting the state of an object after converting it into a stream of bytes.\nThe object can be persisted to a file, a database or memory 
    <hr/>



    47,
       What is Execute Non Query?,
      answer: The ExecuteNonQuery() is one of the most frequently used method in SqlCommand Object, and is used for executing statements that do not return result sets (ie. statements like insert data , update data etc....

    <hr/>48,
      What providers does Ado.net uses? ,
      answer:\nThe .NET Framework provides mainly three data providers, they are\nMicrosoft SQL Server,\nOLEDB,\nODBC.
    <hr/>49,
       How will you close the Database Conenction? ,
      answer:Always close both the DataReader and database connection after access to the database is no longer required.\ndbread.Close()\ndbconn.Close()   
    <hr/>50,
      Which method do you invoke on the DataAdapter control to load your generated dataset with data? ,
      answer:DataAdapter fill () method is used to fill load the data in dataset.\n
    <hr/>51,
       What is difference between Dataset. clone and Dataset.copy? ,
      answer:\nClone: - It only copies structure, does not copy data.\nCopy: - Copies both structure and data.  
    <hr/>
    52,
      What is DataAdapter?,
      answer: A data adapter represents a set of methods used to perform a two-way data updating mechanism between a disconnected DataTable and the database. It aggregates four commands: select, update, insert and delete command. One adapter can only generate and fill one table in a DataSet.   
    <hr/>53,
      What is a Command Object? ,
      answer:The ADO Command object is used to execute a single query against a database. The query can perform actions like creating, adding, retrieving, deleting or updating records. 
    <hr/>54,
      What is basic use of DataView?,
      answer:“DataView” represents a complete table or can be small section of rows depending on some criteria. It is best used for sorting and finding data with in “datatable”.
    <hr/>55,
      What is the use of Connection Object? ,
      answer:The ADO Connection Object is used to create an open connection to a data source. Through this connection, you can access and manipulate a database.
    <hr/>56,
      What is Data Provider?,
      answer:A set of libraries that is used to communicate with data source. \nEg: SQL data provider for SQL, Oracle data provider for Oracle, OLE DB data provider for access, excel or mysql.\nThe data providers refers to a collection of objects that is responsible for providing and maintaining the connection to a database.
    <hr/>57,
      What is the provider and namespaces being used to access oracle database? ,
      answer:system.data.oledb
    <hr/>58,
      Which object is used to add a relationship between Data table objects?,
      answer:The DataRelation object is used to add a relationship between Data table objects.
    <hr/>59,
       What is the use of System.Data namespace in ADO.Net?,
      answer:This contains the basic objects used for accessing and storing relational data such as dataset,datatable and data relation
    <hr/>60,
       What is connection pooling? ,
      answer:Connection pooling refers to the task of grouping database connection in cache to make them reusable because opening new connections every time to a database is a time consuming process. Therefore, connection pooling enables you to reuse already existing and active database connections, whenever required, and increasing the performance of your application. 
    <hr/>61,
        What is the use of Ado.net connection? ,
      answer:Establishes a connection to a specific data source.
    <hr/>




    62,
      What is SqlConnection Object?,
      answer:The connection object establishes connection with a database.\nIt includes the information that is required to connect with a database like the database server name, the database name, user name, password and other parameters.
    <hr/>
    63,
       What two classes are used to read data only? ,
      answer:\nSqlDataReader\nOldDbDataReader\nclasses to read data in a forward directions only.
    <hr/>

    64,
       What is SqlCommand Object?,
      answer:The command object is used for specifying the actions or commands to be executed on a database.\nIt uses the connection object for identifying the database on which to execute commands.
    <hr/>

    65,
      What is the use of System. XML namespace in ADO.Net?,
      answer:System. XML :\nThis contains the basic objects required to create read, store, write and manipulate XML documents according to W3C recommendations.
    <hr/>
    66,
      What is dataset Object?,

      answer:The dataset object is used for manipulating a memory image of a database.\nThe database object that is loaded in memory and which is not connected with the physical database is managed or manipulated through the dataset objects.
    <hr/>

67 . What is SqlDataAdapter Object?,
answer:The object takes the help of all the above objects to work with the underlying database.
It makes use of the connection object to establish connection with the database, 
uses the command object to execute Sql commands on the connected database.
    <hr/>

68.  What is the DataTableCollection?,
answer: An ADO.NET DataSet contains a collection of zero or more tables represented by DataTable objects.
The DataTableCollection contains all the DataTable objects in a DataSet.
    <hr/>

69 . How would you connect to a database by using .NET?,
answer: The connection class is used to connect a .NET application with a database. 
<hr/>
70. When we will go for application state?,
answer:
when ever we want to store the data in web server.
which should be common for all users.  
For example:  In youtube video number of views
    <hr/>

71 . What are the different methods available under sqlcommand class to access the data?
answer:
ExecuteReader - Used where one or more records are returned - SELECT Query.
ExecuteNonQuery - Used where it affects a state of the table and no data is being queried - INSERT, UPDATE, DELETE, CREATE and SET queries.
ExecuteScalar - Used where it returns a single record.
    <hr/>

72. When we will go for connected oriented architecture and when we will go for disconnected oriented architecture?
answer: 
Connected Oriented Architecture (COA):  
Whenever we require a continuous connection with the Database for accessing the data then we will go for COA.  
Disconnected Oriented Architecture (DOA):  
Whenever we doesn’t require a continuous connection with the Database for accessing the data then we will go for DOA.
    <hr/>

73 . How to bind the data to textbox?
answer:  Txtbox1.Text=dr[0]; 
    <hr/>

74. How to bind the data to grid view?,
answer:
Gridview1.datasource=dr;
Gridview1.databind();   
    <hr/>
75 . How to bind the data to label? 
answer: label1.Text=dr[0];
    <hr/>

76. How to bind the data to dropdownlist?
answer:  dropdownList1.datasource=dr;
dropdowList1.DataTextField=dr[1];  
dropdownList1.DatavalueField=dr[0];  
dropdownList1.DataBind();
    <hr/>

77 . Difference between ExecuteReader, ExecuteNonquery, ExecuteScalar?
answer: 
ExecuteReader(): 
It is apre-defined member method of SqlCommand class. 
This method will read or fetch the data from the central database and will return to DataReader object.  
ExecuteNonQuery(): This method will execute the Non-Query command of command object CRUD Operations like INSERT, UPDATE, DELETE, CREATE and so on. 
Then it will return the no. of records which are affected by the command.  
ExecuteScalar(): This method will executes the command object command till the first match. 
This method will avoid the unnecessary scanning of the table, which improves the performance of the application.
    <hr/>
78. How to destroy connection object explicitly?
answer: conn.Dispose()
   


First