In this question the interviewer is expecting two points the first point is dataset is a connect architecture and datareader is a disconnected architecture. Let’s discuss both these points in detail.
Point 1:- ‘DataSet’ is a Disconnected Architecture while ‘DataReader’ is a Connected Architecture.
In order to understand that, below is the sample code for ‘DataSet’ where you can see even after calling the “ObjConnection.Close()” the ”Foreach Loop” is still running. This indicates that the ‘DataSet’ works in Disconnected Architecture.
Similarly, below is the sample code for ‘DataReader’ where you can see that when “ObjConnection.Close()” is called then the “While Loop” does not execute and throws an error. This indicates that the ‘DataReader’ works only in Connected Architecture.
Point 2:- ‘DataSet’ is an in memory representation of database by itself whereas ‘SQLDataReader’ is a flat row and column.
Dataset is an in-memory database with database, tables, columns and rows. While data reader is a flat table with just rows and columns
If you see the dataset object in your visual studio intellisense you should see the complete object hierarchy as shown in the below figure.
If you see the ‘sqldatareader’ in intellisense , its flat table with rows and columns as shown in the below image.
Please click here to see more .NET Interview questions
write a comment