ADo.net Q/A Part 2

on 2:45 AM

Introduction

Full Content

How can we add/remove row’s in “DataTable” object of
“DataSet” ?

“Datatable” provides “NewRow” method to add new row to “DataTable”. “DataTable”
has “DataRowCollection” object which has all rows in a “DataTable” object. Following are the methods provided by “DataRowCollection” object :-
Add
Adds a new row in DataTable
Remove
It removes a “DataRow” object from “DataTable”
RemoveAt
It removes a “DataRow” object from “DataTable” depending on index position of the “DataTable”.

What is basic use of “DataView” ?

“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”.
Dataview has the following method’s :-
Find
It takes a array of values and returns the index of the row.
FindRow
This also takes array of values but returns a collection of “DataRow”.
If we want to manipulate data of “DataTable” object create “DataView” (Using the
“DefaultView” we can create “DataView” object) of the “DataTable” object and use the following functionalities :-
AddNew
Adds a new row to the “DataView” object.
Delete
Deletes the specified row from “DataView” object.

What is the difference between “DataSet” and
“DataReader” ?
Twist :- Why is DataSet slower than DataReader ?
Fourth point is the answer to the twist.
Note:- This is my best question and I expect everyone to answer it. It is asked almost 99%
in all companies....Basic very Basic cram it.
Following are the major differences between “DataSet” and “DataReader” :-
√ “DataSet” is a disconnected architecture, while “DataReader” has live
connection while reading data. If we want to cache data and pass to a
different tier “DataSet” forms the best choice and it has decent XML support.
√ When application needs to access data from more than one table “DataSet”
forms the best choice.
√ If we need to move back while reading records, “datareader” does not support
this functionality.
√ But one of the biggest drawbacks of DataSet is speed. As “DataSet” carry
considerable overhead because of relations, multiple tables etc speed is slower
than “DataReader”. Always try to use “DataReader” wherever possible, as
it’s meant specially for speed performance.

What’s difference between “Optimistic” and
“Pessimistic” locking ?
In pessimistic locking when user wants to update data it locks the record and till then no one can update data. Other user’s can only view the data when there is pessimistic locking.In optimistic locking multiple users can open the same record for updating, thus increase maximum concurrency. Record is only locked when updating the record. This is the most preferred way of locking practically. Now a days browser based application is very common and having pessimistic locking is not a practical solution.

How can we perform transactions in .NET?
The most common sequence of steps that would be performed while developing a
transactional application is as follows:
√ Open a database connection using the Open method of the connection object.
√ Begin a transaction using the Begin Transaction method of the connection
object. This method provides us with a transaction object that we will use
later to commit or rollback the transaction. Note that changes caused by any
queries executed before calling the Begin Transaction method will be committed
to the database immediately after they execute. Set the Transaction property
of the command object to the above mentioned transaction object.
√ Execute the SQL commands using the command object. We may use one or
more command objects for this purpose, as long as the Transaction property
of all the objects is set to a valid transaction object.
√ Commit or roll back the transaction using the Commit or Rollback method of
the transaction object.
√ Close the database connection.

What is difference between Dataset. clone and Dataset.
copy ?
Clone: - It only copies structure, does not copy data.
Copy: - Copies both structure and data.

Can you explain the difference between an ADO.NET
Dataset and an ADO Recordset?
There two main basic differences between recordset and dataset :-
√ With dataset you an retrieve data from two databases like oracle and sql
server and merge them in one dataset , with recordset this is not possible
√ All representation of Dataset is using XML while recordset uses COM.
√ Recordset can not be transmitted on HTTP while Dataset can be.

0 comments:

Post a Comment