none
Looking for DataSet advice... DataSet, DataReader, what suits me? RRS feed

  • Question

  • In short: Should I be using a DataSet or a DataReader?

     

    I'm creating a fairly basic ASP.NET website. It's display only, users can't update data. I'm trying to build it optimised for fairly heavy usage.

    It's also a learning project for me as I'm new to ASP.NET/C# and programming in general

    I started creating the site using a Typed DataSet because at the time that's all I knew about.

     

    Just read a few articles saying DataSets have higher overhead and slower performance, and that perhaps I should be using DataReader instead.

    The main issue I seemed to make out with DataSets, is that they are usually filled with a lot of unneeded data every time the page is called (or the site is run? I couldn't figure out exactly when)

    The data on my website doesn't get updated that much, so why couldn't I just fill the DataSets and cache them for a week or so. Is that possible? Would that overcome the performance issues I've been reading about?

    Currently I've put the code to fill all the tables in my DataSet in the Global.asax Application_Start() area, the thinking being it would limit the DataSets to only be filled every time Application_Start() is triggered. I can't find out when exactly this is triggered though. Every time a new user accesses the website?

    So... Should I be using DataReader? Or is using a DataSet fine in my case, and just somehow limit the amount of times I fill the DataSet

     

    Sunday, April 18, 2010 11:09 AM

Answers

  • Hello,

     

    Welcome to ADO.NET DataSet forum!

     

    I agree that DataSet is higher overhead and slower performance comparing with DataReader.   But from your post, I would recommend you use DataSet for your scenario since it is easier for databinding and especially if you want to share data among different webpage.  

     

    We can make the DataSet as a global variable for your website, and it only needs to be filled once after the page is loaded.   Also since you need to show the data on webpage, it would be easier to do ASP.NET databinding via DataSet.  Here are some ASP.NET DataSets tutorials for your references:

    http://msdn.microsoft.com/en-us/library/aa581776.aspx

    http://www.expertrating.com/courseware/dotnetcourse/DotNet-ASP.Net-9-1.asp

     

    Also I am looking forward to other community members’ ideas. 

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, April 19, 2010 7:25 AM
    Moderator
  • Consider that the DataReader is a "pipe". It needs to remain connected until all of the data is retrieved and you should retrieve the data as fast as humanly possible to release the locks on the database. So the question remains, where do you store the data until the user no longer needs it? Therefore, you need a DataTable (not necessarily a DataSet). With two lines of code you can load a DataTable from a DataReader

    dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    myDataTable.Load dr

    So as to performance and RAM: Fetch JUST what your client needs in the immediate future--never the whole table and rarely a rowset that contains more than a few dozen rows. If they need to scroll through data, get 30 rows and show 15. If they scroll down, go get another 15. Use a smart WHERE clause to reduce the rowset whenever possible.


    __________________________________________________________________
    William Vaughn
    Mentor, Consultant, Trainer, MVP
    http://betav.com
    http://betav.com/blog/billva
    http://www.hitchhikerguides.net

    “Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)”

    Please click the Mark as Answer button if a post solves your problem!

    Thursday, April 22, 2010 8:51 PM
    Moderator

All replies

  • Hello,

     

    Welcome to ADO.NET DataSet forum!

     

    I agree that DataSet is higher overhead and slower performance comparing with DataReader.   But from your post, I would recommend you use DataSet for your scenario since it is easier for databinding and especially if you want to share data among different webpage.  

     

    We can make the DataSet as a global variable for your website, and it only needs to be filled once after the page is loaded.   Also since you need to show the data on webpage, it would be easier to do ASP.NET databinding via DataSet.  Here are some ASP.NET DataSets tutorials for your references:

    http://msdn.microsoft.com/en-us/library/aa581776.aspx

    http://www.expertrating.com/courseware/dotnetcourse/DotNet-ASP.Net-9-1.asp

     

    Also I am looking forward to other community members’ ideas. 

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, April 19, 2010 7:25 AM
    Moderator
  • Hi,

     

    I am writing to check the status of the issue on your side.  Would you mind letting me know the result of the suggestions? 

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 22, 2010 1:38 AM
    Moderator
  • Consider that the DataReader is a "pipe". It needs to remain connected until all of the data is retrieved and you should retrieve the data as fast as humanly possible to release the locks on the database. So the question remains, where do you store the data until the user no longer needs it? Therefore, you need a DataTable (not necessarily a DataSet). With two lines of code you can load a DataTable from a DataReader

    dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    myDataTable.Load dr

    So as to performance and RAM: Fetch JUST what your client needs in the immediate future--never the whole table and rarely a rowset that contains more than a few dozen rows. If they need to scroll through data, get 30 rows and show 15. If they scroll down, go get another 15. Use a smart WHERE clause to reduce the rowset whenever possible.


    __________________________________________________________________
    William Vaughn
    Mentor, Consultant, Trainer, MVP
    http://betav.com
    http://betav.com/blog/billva
    http://www.hitchhikerguides.net

    “Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)”

    Please click the Mark as Answer button if a post solves your problem!

    Thursday, April 22, 2010 8:51 PM
    Moderator