开发者

What to use for a datagrid with a lot of data?

开发者 https://www.devze.com 2023-01-21 13:53 出处:网络
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

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 开发者_如何学JAVAfor 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


I'd use paging.

You can also accomplish this using stored procedures.


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


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消