Interview Questions and Answers
Interview Questions and Answers
Interview Questions and Answers
Net Interview Questions and Answers for dot net developers with
sample code and detailed explanations on Dataset, Datareader, Datatable, DataView, Connection
object, Transactions, SQL Commands, Data adapter, Data Providers, Locking, Connection pooling
and Connection String.
1) What is ADO.NET ?
ADO.Net is one of the major component of .Net Framework, which is designed to connect to
databases like Oracle, MySQL, SQL Server, MS Access etc. and work with data stored in them.
ADO.Net provides in built classes to connect with Databases like Oracle, MySQL, SQL Server, MS Access etc.
Provides in built classes to do data manipulation operations like Insert, Update, Delete and Select data.
Provides data providers for specific databases for efficient interactions with DB. Example - ODP.Net provider for
Oracle.
Tight integration with XML
Provides functionality to combine data from different data sources
Disconnected Data architecture for better performance
Batch Update To update n no of rows in a database table in a single call from a program thus by avoiding
round trip to database.
Data Paging To read data from a certain index
Connection Details To get detailed info about connections like buffer information, cursor details etc.
DataSet.RemotingFormat Property To make dataset serialized in Binary
DataTable's Load and Save Methods For XML interactions.
ADO
ADO.Net
ADO.Net have Data Adapter and Data set
ADO.NET uses XML for passing the data
ADO.Net works in Disconnected manner
By leveraging known meta data at design time, ADO.Net provide better runtime performance and more
consistent runtime behaviour
ADO.Net Support both client side and server side cursors
Fundamental Objects of ADO.Net are DataReader and DataSet. DataSet Object can have a set of
DataTables and relationships between these tables. DataSet can be used in disconnected connection
with DB. DataReader is used to read the read only data from a database.
DataReader is used to fetch data from a database in a much faster way. Since the rows are fetched one
at a time, load on the network will be low. Since DataReader is read only, transactions are not
allowed. Since it support forward only data iteration, random data fetch is not supported.
Connection Objects is used to establish a connection between an application and databases like
Oracle, MySQl, SQL Server etc. Once connection is established, SQL Commands like insert, update,
delete and select can be executed. Scope of a connection object can be local or global. If local
connection object is used, it should be closed after SQL commands are executed.
using System.Data.SqlClient;
try
{
// Open DB connection
string Connection = "server=localhost; uid = UserName ; pwd = Password ; database =
DemoDB";
SqlConnection conn = new SqlConnection(Connection);
conn.Open();
}
catch ( Exception ex )
{
// Log Exceptions
}
finally
{
conn.Close ( ) ; // Close the connection
}
When one or more related SQL Commands are executed and if any one statement failed to execute,
we need to rollback the entire related operations that has been executed. In such a scenario,
Transactions are used.
using System.Data.SqlClient;
try
{
string Connection = "server=localhost; uid = UserName ; pwd = Password ; database =
DemoDB";
SqlConnection con = new SqlConnection(Connection);
con.Open();