Is datareader quicker than dataset when populating a datatable?

前端 未结 8 1113
一个人的身影
一个人的身影 2020-11-29 11:43

Which would be quicker.

1) Looping a datareader and creating a custom rows and columns based populated datatable

2) Or creating a dataAdapter object and just

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 12:08

    Assuming you actually want all the data coming back from the database, the time taken at the database and on the network is almost certain to dwarf the time taken in-process to populate data structures in memory.

    Yes, in some cases you might get a small saving by using DataReader - and in particular if you want to stream the data it may be useful - but if you do actually need it all, I'd stick with the simplest code. If you believe that the DataSet population is causing a significant performance problem, profile it and then try to improve it.

提交回复
热议问题