views:

32

answers:

4

Hi,

Found this interesting interview question:

You need to display the sales data for your division for the past 5 years in a DataGrid on a Web Form. Performance is very important. What would be the best strategy to use in retrieving the data?

  • a)Use a DataReader object to retrieve the data for the DataGrid.
  • b)Use a DataSet object to retrieve the data for the DataGrid.
  • c)Use a simple select statement as the data source for the DataGrid.
  • d)Use a cached XML file as the data source and retrieve the data with a DataSet.

My answer is c) but I am not too sure Can anyone point me to the right answer and explain it to me please Thanks

+3  A: 

I'd use paging.

You can also accomplish this using stored procedures.

Robert Greiner
Yes, this is the right way to do it, IMO. +1 but I'm out of votes :[
Alex
haha, that's OK Alex. Thanks anyway :P
Robert Greiner
+1  A: 

Basically any time a test mentions performance and DataReader and DataSet, the rule of thumb is DataReader == fast and DataSet == slow.

Greg
Personally my answer would be "Buy a grid control that does server-side paging if it's that important"
Greg
+1  A: 

I'd probably say choice A of the answers provided, but paging is definitely the more correct answer. DataSets are slow and load the whole table while DataReader is really fast, just iterating over the records.

Using a select statement as the datasource is just bad practice and never recommended.

Chris Conway
A: 
  1. If performance is very important then don't use a datagrid, use a repeater or an ordinary loop.
  2. I would assume a cached XML file (memomry) is faster than retrieving data from a database BUT could also use a considerable amount of memory, so not the right answer I think.
  3. A select statement and a DataReader is very much alike, but you have some more out-of-the-box features with a DataReader, so that would be my answer.
danielovich
How do you even execute a select statement on a database in .net without a DataReader or DataAdapter?
Greg