Interview Questions and Answers Book
Interview Questions and Answers Book
All rights reserved. No part of this book can be reproduced or stored in any retrieval system, or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording, uploading on server and scanning without
the prior written permission of the author.
The author of this book has tried his best to ensure the accuracy of the information described in this book.
However, the author cannot guarantee the accuracy of the information contained in this book. The author will
not be liable for any damages, incidental or consequential caused directly or indirectly by this book. Further,
readers should be aware that the websites or reference links listed in this book may have changed or disappeared
between when this book was written and when it is read.
All other trademarks referred to in this book are the property of their respective owners.
Release History
• Initial Release 1.0.0 - 24th June 2019
1
Page
About Dot Net Tricks
Dot Net Tricks is founded by Shailendra Chauhan (Microsoft MVP), in Jan 2010. Dot Net Tricks came into existence
in the form of a blog post over various technologies including .NET, C#, SQL Server, ASP.NET, ASP.NET MVC,
JavaScript, Angular, Node.js and Visual Studio etc.
The company which is currently registered by a name of Dot Net Tricks Innovation Pvt. Ltd. came into the shape
in 2015. Dot Net Tricks website has an average footfall on the tune of 300k+ per month. The site has become a
cornerstone when it comes to getting skilled-up on .NET technologies and we want to gain the same level of trust
in other technologies. This is what we are striving for.
We have a very large number of trainees who have received training from our platforms and immediately got
placement in some of the reputed firms testifying our claims of providing quality training. The website offers you
a variety of free study material in the form of articles.
• .NET Development
• Frond-end Development
• Cloud
• DevOps
• Programming Languages
• Database - SQL and NoSQL
• Mobile Development and many more...
DotNetTricks Pro unlocks the access of DotNetTricks premium features like unlimited access to all courses, source
codes, assessments. Get help over email or phone. Upgrade your skills with curated learning paths tailored to
today's developers and technology needs. Learn new skills and discover the world of possibilities with step-by-
step guidance.
2
Page
Start your journey today to learn coding. Because learning to code is the first step and foreword to advance your
career. The detail about Dot Net Tricks Pro can be found here: https://www.dotnettricks.com/pro-membership
For a beginner who needs regular guidance, we have a fully packed Master Courses. They are almost equal to
semester courses taught in engineering colleges when it comes to length, breadth of content delivery, the only
difference instead of 5-6 months, they take approx. 16-weekend classes (2 months).
Corporate Training
Dot Net Tricks having a pool of mentors who help the corporate to enhance their employment skills as per
changing the technology landscape. Dot Net Tricks offers customized training programs for new hires and
experienced employees through online and classroom mode. As a trusted and resourceful training partner, Dot
Net Tricks helps the corporate to achieve success with its industry-leading instructional design and customer
training initiatives.
Apart from these, we also provide on-demand boot camps and personalized project consultation.
• .NET Development
•
3
Frond-end Development
Page
• Cloud
• DevOps
• Programming Languages
• Database - SQL and NoSQL
• Mobile Development and many more….
Technical Recruiting
We provide full technical staffing service which suits our client needs. Our technical recruiters search across the
world to find highly skilled professionals that will fit our clients need. If you are looking for a job change, do share
your resume at [email protected]. Dot Net Tricks will help you to find your dream job in MNCs.
Join us today, learn to code, prepare yourself for interviews, and get hired!
4
Page
Dedication
My mother Mrs Vriksha Devi and my wife Reshu Chauhan deserve to have their name on the cover as
much as I do for all their support made this possible. I would like to say thanks to all my family members
Virendra Singh(father), Jaishree and Jyoti(sisters), Saksham and Pranay(sons), friends, to you and to
readers or followers of my articles at https://www.dotnettricks.com/mentors/shailendra-chauhan to
encourage me to write this book.
-Shailendra Chauhan
5
Page
Introduction
Writing a book has never been an easy task. It takes a great effort, patience and consistency with strong
determination to complete it. Also, one should have a depth knowledge over the subject is going to write.
So, what where my qualification to write this book? My qualification and inspiration come from my enthusiasm
for and the experience with the technology and from my analytic and initiative nature. Being a trainer, analyst,
consultant and blogger, I have thorough knowledge and understandings of .NET technologies. My inspiration and
knowledge have also come from many years of my working experience and research over it.
• ADO.NET Architecture.
• Connected and Disconnected Architecture.
• Data Providers and Connection Pooling.
• How to use Connection and command objects.
• Using DataReader and DataSets.
• Data Adapter and DataView.
• Using and Managing DataTable.
• Strongly typed datasets and untyped data sets.
• Use of Transaction in ADO.NET.
Our best wishes always with you for your learning and growth!
6
Page
About the Author
Shailendra Chauhan - An Entrepreneur, Author, Architect,
Corporate Trainer, and Microsoft MVP
He is the Founder and CEO of DotNetTricks which is a brand when it comes
to e-Learning. DotNetTricks provides training and consultation over an array
of technologies like Cloud, .NET, Angular, React, Node and Mobile Apps
development. He has been awarded as Microsoft MVP three times in a row
(2016-2018).
He has changed many lives from his writings and unique training programs.
He has a number of most sought-after books to his name which have helped
job aspirants in cracking tough interviews with ease.
Moreover, and to his credit, he has delivered 1000+ training sessions to professionals worldwide in Microsoft
.NET technologies and other technologies including JavaScript, AngularJS, Node.js, React and NoSQL Databases.
In addition, he provides Instructor-led online training, hands-on workshop and corporate training programs.
Shailendra has a strong combination of technical skills and solution development for complex application
architecture with proven leadership and motivational skills have elevated him to a world-renowned status,
placing him at the top of the list of most sought-after trainers.
“I always keep up with new technologies and learning new skills to deliver the best to my students,” says
Shailendra Chauhan, he goes on to acknowledge that the betterment of his followers and enabling his students to
realize their goals are his prime objective and a great source of motivation and satisfaction.
Shailendra Chauhan - “Follow me and you too will have the key that opens the door to success”
7
Page
How to Contact Us
Although the author of this book has tried to make this book as accurate as it possible but if there is something
strikes you as odd, or you find an error in the book please drop a line via e-mail.
• [email protected]
• [email protected]
We always happy to hear from our readers. Please provide your valuable feedback and comments!
You can follow us on YouTube, Facebook, Twitter, LinkedIn and Google Plus or subscribe to RSS feed.
8
Page
Table of Contents
ADO.NET Interview Questions & Answers ...................................................................... 1
Release History ....................................................................................................................................................1
About Dot Net Tricks ..........................................................................................................................................2
Dot Net Tricks Courses .......................................................................................................................................2
Dot Net Tricks Live Training ................................................................................................................................3
Dot Net Tricks eBooks ........................................................................................................................................3
Technical Recruiting ...........................................................................................................................................4
Dedication ...........................................................................................................................................................5
Introduction ........................................................................................................................................................6
About the Author ................................................................................................................................................7
How to Contact Us...............................................................................................................................................8
References ..................................................................................................................... 26
Learn. Build. Empower. .................................................................................................. 26
10
Page
1
Introducing ADO.NET
Q1. What is ADO.NET?
Ans. ADO.NET is an evolutionary improvement to Microsoft ActiveX Data Objects (ADO). ADO.NET is an
integral part of the .NET Framework which provides access to relational data, XML documents, and application
data.
11
.NET Framework Data Provider: They actually talk to the database to assist in data retrievals and updates.
Page
Class Description
Connection Connection represents a connection to the database system.
Command Represents SQL query or command to be executed at the database management system.
DataAdapter DataAdapter class connects to the database system, fetch the record and fill the DataSet. It
contains four different commands to perform database operations; Select, Update, Insert and
Delete.
DataReader A stream that reads data from the database in connected design.
DataSet: The DataSet is a local buffer of tables or a collection of disconnected record sets and hold actual data.
Its main components are given below:
Class Description
DataTable DataTable is used to contain the data in tabular form using rows and columns.
DataRow Represents a single record or row in DataTable.
DataRow DataRow Represents a single record or row in DataTable.
DataColumn DataColumn Represents a column or field of DataTable.
DataRelation DataRelation Represents the relationship between different tables in a DataSet.
Constraint Represents the constraints or limitations that apply to a particular field or column.
• Performance and scalability: ADO.NET offer high performance and scalability than ADO. In ADO.NET,
disconnected cached data in XML helps in performance and scalability
• Optimized SQL Provider: ADO.NET SQL Server Data Provider that is highly optimized for interaction with
MS-SQL Server. It uses SQL Server’s own TDS (Tabular Data Stream) format for exchanging information.
• XML Support (Data transfer in XML format): ADO.NET data is cached and transferred in XML (Extensible
Markup Language) format. XML provide fast access of data for desktop and distributed applications.
• Disconnected Model: In ADO.NET, the DataSet operates in an entirely disconnected fashion. The
disconnected model makes the DataSet to be unaware of the data source of its data. In this way you can
use an unlimited number of supported data sources to be plugged into code without any hassle.
ADO ADO.NET
ADO has RecordSet to access and manipulate data. ADO.NET has DataSet to access and manipulate data.
In RecordSet, there can be one table. To contains In ADO.NET, a DataSet can have multiple tables.
more than one tables, you need to perform inner join.
XML support is less as compared to ADO.NET XML support is high.
It supports only connected model. It supports both connected and disconnected model.
12
Page
Q5. What is connected environment in ADO.NET?
Ans. In a connected environment while querying or modifying the data source, you are connected to it. The
components of Connected environment are given below:
13
Page
Q7. What are the most commonly used namespaces in ADO.NET?
Ans. Following are the most commonly used namespace in ADO.NET.
1. System.Data
2. System.Data.OleDb
3. System.Data.SqlClient
4. System.Data.OracleClient
5. System.Xml
Q9. What are the different types of data providers in .NET framework?
Ans. Following are the different data providers in .NET framework.
System.Data.Odbc .NET Data Provider for ODBC Provides access to databases exposed by
using ODBC.
Page
System.Data.OracleClient .NET Data Provider for Oracle Provides access to Oracle database version 8
or later versions.
• SQL Server managed provider: The SQL Server managed provider is used with SQL server and is a very
efficient way of communicating with SQL Server.
• OLEDB managed provider: OLEDB managed provider is used to communicate with any OLEDB compliant
database like MS Access, Oracle, DB2 etc.
15
Page
2
Connection and Command
Q1. What is Connection Pooling?
Ans. Grouping of database connections in cache to make them reusable is called connection pooling. You know
that opening new connections every time to a database is a time-consuming process. And so, connection pooling
enables us to reuse already existing and active database connections, whenever required. In this way it increases
the performance of our application.
<connectionStrings>
<add name="strCon" connectionString="Data Source=dotnet-tricks.com;Initial Catalog=dotnet-
tricks; Persist Security Info=True; Pooling=true; User ID=tricks;Password=123@dt"
providerName="System.Data.SqlClient"/>
</connectionStrings>
try
16
{
conn.Open();// Open DB connection
Page
2. ExecuteReader(): It executes a select a statement and return the rows returned by the select statement as a
DataReader. The return type of this method is a DataReader.
3. ExecuteScalar: It executes a SQL statement which returns a single value, like avg, min, max etc. The return
type of this method is object.
try
{
conn.Open();// Open DB connection
// Log Exceptions
}
finally
{
conn.Close(); // Close the connection
}
try
{
conn.Open();// Open DB connection
}
catch (Exception ex)
{
// Log Exceptions
}
finally
{
conn.Close(); // Close the connection
}
For example, if two persons are accessing same table, if one person executes an insert, other person will be able
to access the newly inserted row only after the first person commit the transaction.
18
ReadUncommitted: This is a state of transaction where changes in database made by a user can be reflected to
Page
others before the first user commits the transaction. Transactions running at the Read Uncommitted level do not
issue shared locks to prevent other transactions from modifying data read by the current transaction. This does
not prevent dirty reads.
Pessimistic: In Optimistic locking multiple users can open the same record for modification, thus increase
maximum concurrency. The record is only locked when it is modified by someone and starts committing it to the
database.
19
Page
3
DataReaders and DataSets
Q1. What is DataReader in ADO.NET?
Ans. A DataReader object is a forward-only and read-only cursor. It needs a live connection with the data
source to fetch the result.
1. DataReader object cannot be directly instantiated. Instead, it must be called by ExecuteReader method
of the Command object.
2. By using DataReader your application performance can be increased since it retrievs data as soon as it is
available, and by default it stors only one row at a time in memory.
3. A DataReader provides fast access when a forward-only sequential read is needed.
4. Be sure to close the connection when done using data reader. Otherwise, the connection stays alive until
it is explicitly closed.
DataReader DataSet
Works in connected mode only. Works in disconnected mode only.
Can navigate forward only. Can navigate backward and forward.
Data is read only. Data is editable.
Can contain only one row/record at a time. It cached the entire data. Hence contain multiple records.
Faster as compared to DataSet. Slower as compared to DataReader.
Need to open or close connection explicitly. Do not need to open or close the connection.
20
Page
Q4. What is difference between DataSet and RecordSet?
Ans. The difference between DataSet and RecordSet is given below:
DataSet RecordSet
Supports disconnected approach. Supports connected approach.
A DataSet can represent a relational database in A RecordSet is able to load the structure and data of only
memory along with tables, relations, and views. one table at a time.
Data in a DataSet is cache, rather than being A RecordSet can contain one record at a time.
loaded on demand.
DataSet can be transmitted over http protocol. A RecordSet cannot be transmitted over http protocol.
There is no concept of cursor in DataSet There is concept of cursor in RecordSet
You can use foreach loop to move through the RecordSet have current record pointer and so you cannot
data. use foreach loop.
1. GetChanges()– It returns a copy of the DataSet containing all changes made to it since it was last loaded,
or since the last time AcceptChanges was called.
2. HasChanges()– It returns a boolean value (true or false) to indicates any changes occurred to DataSet
including new, deleted, or modified rows. If changes occur, it returns true otherwise returns false.
3. RejectChanges()– It rolls back all the changes made to the DataSet object since it was created, or since
the last time AcceptChanges was called.
Adapter.Update(ds, "tbl_Employee");
Q8. What are basic methods of DataAdapter?
Ans. Following are the methods of DataAdapter:
Methos Description
Fill This method fills data records from a DataAdapter to a DataSet object by executing the Select
statement.
FillSchema This method adds a DataTable with its schema to a DataSet. It creates an empty table in the
DataSet object with all the corresponding constraints.
Update This executes the Insert, Update, or Delete SQL statement to update the original data source
with the changes made to the content of the DataSet.
Clone Copy
The Clone() method copies only the structure of a The Copy() method copies the structure as well as
DataSet. The structure of a DataSet includes all the the data stored in the DataSet.
relations, constraints and the DataTables.
DataTableName.Rows[index].Delete();
DataTableName.AcceptChanges();
23
Page
4
Advanced DataSets and
Transactions
Q1. What is Strongly Typed DataSets?
Ans. A Typed DataSet is a class that derives from a DataSet and contains all the methods, events, and properties
of a DataSet. It is stored in an .xsd file and type checking is done at design time using the .xsd definitions. A Typed
dataset binds with the database tables at design time and contains all the schema information at design.
Q3. What are the different methods in DataSet to manipulate with XML?
Ans. The methods to create, read and return XML in DataSet are given below:
//start transaction
24
transaction = con.BeginTransaction();
try
Page
{
SqlCommand cmd = new SqlCommand("<your sql statement1 here>", con, transaction);
cmd.ExecuteNonQuery();
cmd = new SqlCommand("<your sql statement2 here>", con, transaction);
cmd.ExecuteNonQuery();
//commit db changes
transaction.Commit();
}
catch (SqlException sqlError)
{
//rollback/undo db changes
transaction.Rollback();
}
con.Close();
25
Page
References
Master in-demand job skills with our step by step and project-based courses. Learn to start a new career, with our
curated learning paths tailored to today's developers and technology needs. Learn to code, prepare yourself for
interviews, and get hired!
26
Page