Generics vs datasets RRS feed

  • Question

  • Hi,
    I have a database in which most of the tables will be grow by approximately 1 lakh records per month.

    Now we are using datasets to hold the records for manipulation and displaying purpose (using sqlhelper class as DAL).

    But now we read a article it says,using generics will improve the performance.In that what they are doing was using a executereader against the table in a loop and read the records and write in to collection object using generics(Using provider pattern).

    My question is which one will be best,since writing into collection requires looping which opens db for every record which is extensive.But in other hand they are arguing that using datasets will increase the page weight.

    In either case we are not retrieving more than 20 records at a time.

    Please clarify me which one to use.

    knowledge glows
    Tuesday, December 8, 2009 7:28 AM


  • The first question is: "Do you have a performance problem". If not don't try to optimize something that isn't broken.

    Readers can be faster used properly (in fact DataAdapter uses readers to fill the dataset so it's only logical that skipping the middle man, dataset, will improve performance). Used improperly, like the scenario you mention with opening the DB for every record, it will degrade performence.

    They are right that DataSets might increas page weight, especially if you use ViewState to store it. Readers and small objects will be faster and have a smaller memory footprint. But then again, if you don't have a performance / memory problem it doesn't really matter. (20 records is a very small amount given that you don't have 1million + users).

    Using generics (or your own classes I'm guessing the article is about) will have other benefits for development and maintence that might be worth investigating as well. If you build a lot of bussiness logic based on your data, typed objects with properties and methods i usually a much better option then the unstructured nature of a dataset.

    I hope this clarifies the issue somewhat.

    Patrik Löwendahl [C# MVP] - blog: http://blog.lowendahl.net
    Tuesday, December 8, 2009 8:49 AM