Is datareader quicker than dataset when populating a datatable?

前端 未结 8 1100
一个人的身影
一个人的身影 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:12

    As with many questions like this the answer is: depends.

    If you don't know the structure of your data up front and are creating TableAdapters on the fly, then the dynamic DataTable would be more efficient. There is a good deal of code generation involved in creating a TableAdapter.

    However, if you know the structure of your data up front then the question becomes, How much functionality do I need?

    If you need a full CRUD implementation then there are some efficiencies gained by using a TableAdapter rather than writing all that CRUD code yourself. Also, the TableAdapter implementation is OK (not great). If you need something more efficient then you may be better off using nHibernate or some other ORM.

    If you don't need a full CRUD implementation (i.e., this is a read-only solution) and know your data structure up front, then you'll have to test the efficiency of a TableAdapter read-only implementation against a dynamically generated DataTable. If I were a betting man I'd put my money on the TableAdapter implementation since you bind data once and read it multiple times.

提交回复
热议问题