简体   繁体   中英

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

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

I'd use paging .

You can also accomplish this using stored procedures .

基本上每当测试提到性能和DataReader和DataSet时,经验法则是DataReader == fast和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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM