Tuesday, 15 September 2015

Page 8 ASP.Net Interview Questions and Answers

71. What is the difference between a DataReader and a DataSet? 
1. DatReader works on a Connection oriented architecture.
2. DataReader is read only, forward only. It reads one record at atime. After DataReader finishes reading the current record, it moves to the next record. There is no way you can go back to the previous record. So using a DataReader you read in forward direction only.
3. Updations are not possible with DataReader.
4. As DataReader is read only, forward only it is much faster than a DataSet.
1. DataSet works on disconnected architecture.
2. Using a DataSet you can move in both directions. DataSet is bi directional.
3. Database can be updated from a DataSet.
4. DataSet is slower than DataReader.

72. How can we load multiple tables in a Dataset?
objCommand.CommandText = "Table1"
objDataAdapter.Fill(objDataSet, "Table1")
objCommand.CommandText = "Table2"
objDataAdapter.Fill(objDataSet, "Table2")
Above is a sample code, which shows how to load multiple “Data Table” objects in one “Dataset” object. Sample code shows two tables “Table1” and “Table2” in object ObjDataSet.
lstdata.DataSource = objDataSet.Tables("Table1").DefaultView
In order to refer “Table1” Data Table, use Tables collection of Datasets and the Default view object will give you the necessary output.

73. How can we add relation between tables in a Dataset?
Dim objRelation As DataRelation
Relations can be added between “Data Table” objects using the “Data Relation” object. Above sample, code is trying to build a relationship between “Customer” and “Addresses” “Data table” using “Customer Addresses” “Data Relation” object.

74. What is the use of Command Builder?
Command Builder builds “Parameter” objects automatically. Below is a simple code, which uses command builder to load its parameter objects.

Dim pobjCommandBuilder As New OleDbCommandBuilder(pobjDataAdapter)
Be careful while using “Derive Parameters” method as it needs an extra trip to the Data store, which can be very inefficient.

75. What are the two fundamental objects in ADO.NET?
Data reader and Dataset are the two fundamental objects in ADO.NET.

76. What are major difference between classic ADO and ADO.NET?
Following are some major differences between both :-
• In ADO we have recordset and in ADO.NET we have dataset.
• In recordset we can only have one table. If we want to accommodate more than one tables we need to do inner join and fill the recordset. Dataset can have multiple tables.
• All data persist in XML as compared to classic ADO where data persisted in Binary format also.

77. What is the use of data adapter?
These objects connect one or more Command objects to a Dataset object. They provide logic that would get data from the data store and populates the tables in the Dataset, or pushes the changes in the Dataset back into the data store.
• An OleDbDataAdapter object is used with an OLE-DB provider
• A SqlDataAdapter object uses Tabular Data Services with MS SQL Server.

78. 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.

79. How can we save all data from dataset?
Dataset has “Accept Changes” method, which commits all the changes since last time “Accept changes” has been executed.
Note :- This book does not have any sample of Acceptchanges. We leave that to readers as homework sample. But yes from interview aspect that will be enough.

80. What are the 3 major types of connection objects in ADO.NET?
OleDbConnection object : Use an OleDbConnection object to connect to a Microsoft Access or third-party database, such as MySQL. OLE database connections use the OleDbDataAdapter object to perform commands and return data.
SqlConnection object : Use a SqlConnection object to connect to a Microsoft SQL Server database. SQL database connections use the SqlDataAdapter object to perform commands and return data.
OracleConnection object : Use an OracleConnection object to connect to Oracle databases. Oracle database connections use the OracleDataAdapter object to perform commands and return data. This connection object was introduced in Microsoft .NET Framework version 1.1.

81. can we connect two dataadapters to same data source using single connection at same time?
yes,we can connect two dataadapters to same datasource using single connection at same time.
There is a technology in ado.net 2.0 called MARS usinng Mars in connection string we can do it.
for eg:
cn.ConnectionString = "server=(local); database=employee; integrated security=sspi; MultipleActiveResultSets=True";

82. What is Delegate?
Delegate is an important element of C# and is extensively used in every type of .NET application. A delegate is a class whose object (delegate object) can store a set of references to methods.

More Questions & Answers:-
Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8

No comments:

Post a Comment