Wednesday 30 March 2011

DataSet Interview Questions

What is a DataSet ?

A DataSet is an in memory representation of data loaded from any data source.

How can we load multiple tables in to Dataset?

DataSet ds=new DataSet();
SqlDataAdapter dap=new SqlDataAdapter(Select * from <tablename>,<connection1>);
dap.Fill(ds,"TableOne");
SqlDataAdapter dap1=new SqlDataAdapter(Select * from <tablename>,<connection1>);
dap1.Fill(ds,"tableTwo");


How do we update a Dataset in ADO.Net and How do we update database through Dataset?

a. Update a DataSet:

DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(Query,connection);
adp.fill(ds);
Again we can add/update Dataset as below
SqlDataAdapter adp1 = new SqlDataAdapter(Query1,connection);
Adp1.fill(ds);

b. Update database through DataSet:

SqlCommandBuilder cmd = new SqlCommandBuilder(adp);
foreach(DataRow dr in ds.Table[0].Rows)
{
dr[“column Name”] = “value”;
adp.Update(ds);
}


What we do with the object of ado.net dataset after using it?Can we dispose it or can we set it nothing?Is it must or not?

we use dispose

If a table contains 20000 records . In a page at each time 100 records to be displayed.
What are the steps u will take to improve performance? will you use dataset or datareader?


We should go for DataSet as DataReader doesnot allow navigation between data. Suppoose we are seeing 1500 data and we want to see previous data in DataReader it is not possible but with DataSet we can do this.

what is typed and untyped dataset?
Typed DataSet has a schema and an Untyped DataSet does not have one.
It should be noted that the Typed Datasets have more support in Visual studio.

What is a DataTable?

A DataTable is a class in .NET Framework and in simple words a DataTable object represents a table from a database.

How do you merge two datasets into the third dataset in a simple manner?

Use DataSet1.Merge (DataSet2) method to merge two datasets and copy DataSet1 to DataSet3.

How to generate XML from a dataset and vice versa?

We can use WriteXml() and ReadXml() methods of DataSet Object.

What is Dataset object?

The DataSet provides the basis for disconnected storage and manipulation of relational data. We fill it from a data store, work with it while disconnected from that data store, then reconnect and flush changes back to the data store if required.

How can we save all data from dataset ?

Dataset has “AcceptChanges” method which commits all the changes since last time “Acceptchanges” has been executed.

How can we check that some changes have been made to dataset since it was loaded ?
Twist :- How can we cancel all changes done in dataset ? , How do we get values which are changed in a dataset ?


For tracking down changes Dataset has two methods which comes as rescue “GetChanges “and “HasChanges”.

GetChanges Return’s dataset which are changed since it was loaded or since Acceptchanges was executed.
HasChanges This property indicate’s has any change’s been made since the dataset was loaded or
acceptchanges method was executed.

 If  we want to revert or abandon all change’s since the dataset was loaded use “RejectChanges”.

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

”DataTable” has “DataRowCollection” object which has all rows in a “DataTable” object.
Following are the methods provided by “DataRowCollection” object :-

Add: Add’s a new row in DataTable
Remove: Remove’s a “DataRow” object from “DataTable”
RemoveAt: Remove’s a “DataRow” object from “DataTable” depending on index position of  the “DataTable”.

What’s difference between DataSet.Clone and DataSet.Copy ?

Clone: - It only copies structure, does not copy data. Copy: - Copies both structure and data.

1 comment:

  1. Thanks for sharing this useful interview questions.

    Placement Papers

    ReplyDelete