none
ASP.NET DataAccess RRS feed

  • Question

  • Hi Guyz!

    This is a quite a simple question. A simple webapplication has to access the database. I can do so through the data set and also by making a data class for the tables in the database (e.g customer) and methods to copy dataset rows into the class and use that class in my webapplication.

    I just need to know what is a better approach? datasets used directly in webapplication or through data classes?

    For eg.

    DB Table: Customer (Id, Name)

    I make a class library project called 'dataclass': Make a typed dataset for the db and a class called customer with the properties Id and Name.

    I make a class library project called 'Data Access': Populate my dataset using SELECt queries.

    I make a class library project called 'Processing;: class called 'customers' where the dataset row copies over to the customer class object.

    In my web application i call the customers class with the function that returns the 'customer' object and use that in my application. As you can see, i use objects to communicate from the webapp to the processing.dll and then convert the objects back to dataset for dataaccess.

    What i dont understand is the benefit of this approach rather then simply using a dataset and no need to have an object class at all. Infact it seems if i want to make a change in the data base, that would need to be reflected on so many places so why dont i use simply the dataset?

    Any thoughts would be greatly appreaciated!

    Thanks.
    Tuesday, November 13, 2007 2:28 PM

Answers

  • This has been discussed at length many, many times.  It boils down to a political battle in most cases which each side declaring themselves the winner.  I recommend you search for articles comparing DataSet to DataReader. These articles will identify the circumstances under which you should use DataSets and when to use DataReader. 

     

    In summary, though, here are the advantages and disadvantages (without explanations):

    DataSets - Advantages:

    • Great support in the designers and controls like DataGridView
    • Auto-generation of code
    • Strongly or weakly typed depending upon need
    • Support for change detection, merging of data and updating databases
    • Serialization/deserialization support
    • Constraint and key validation
    • Self-describing and can be programmatically built up as a database in memory
    • Disconnected from db allowing offline operation

    DataSets - Disadvantages:

    • Takes up a lot of memory due to schema
    • Slower than DataReader because of building and managing schema

    DataReader  - Adv:

    • Fast
    • Supports all data types, including binary (not sure DataSets support this)
    • Allows for the creation of custom business rules in the BL to support logic not doable in database
    • Small memory footprint including the ability to filter out data without using up memory

    DataReader - Disadv:

    • Requires a persistent connection to the DB while open
    • Requires writing code to read from DB
    • Requires writing business classes
    • No constraint support directly

    In general I prefer DataReader for speed and because I always create business classes because I expose class libraries but it requires a lot of additional code.  DataSets are great for web apps where you are predominantly working with grids since the grid can display, edit and update the data with almost no code.  Memory size is a big issue though.  DataSets are not designed to hold a large # of rows due to the memory overhead.  Web apps are more impacted than client apps.  It would be reasonable to say that you shouldn't try to load 1000 rows into a DataSet as it'll eat up memory.  Then again you shouldn't really be doing that anyway.  IMHO.

     

    Michael Taylor - 11/13/07

    http://p3net.mvps.org

     

     

    Tuesday, November 13, 2007 3:17 PM

All replies

  • This has been discussed at length many, many times.  It boils down to a political battle in most cases which each side declaring themselves the winner.  I recommend you search for articles comparing DataSet to DataReader. These articles will identify the circumstances under which you should use DataSets and when to use DataReader. 

     

    In summary, though, here are the advantages and disadvantages (without explanations):

    DataSets - Advantages:

    • Great support in the designers and controls like DataGridView
    • Auto-generation of code
    • Strongly or weakly typed depending upon need
    • Support for change detection, merging of data and updating databases
    • Serialization/deserialization support
    • Constraint and key validation
    • Self-describing and can be programmatically built up as a database in memory
    • Disconnected from db allowing offline operation

    DataSets - Disadvantages:

    • Takes up a lot of memory due to schema
    • Slower than DataReader because of building and managing schema

    DataReader  - Adv:

    • Fast
    • Supports all data types, including binary (not sure DataSets support this)
    • Allows for the creation of custom business rules in the BL to support logic not doable in database
    • Small memory footprint including the ability to filter out data without using up memory

    DataReader - Disadv:

    • Requires a persistent connection to the DB while open
    • Requires writing code to read from DB
    • Requires writing business classes
    • No constraint support directly

    In general I prefer DataReader for speed and because I always create business classes because I expose class libraries but it requires a lot of additional code.  DataSets are great for web apps where you are predominantly working with grids since the grid can display, edit and update the data with almost no code.  Memory size is a big issue though.  DataSets are not designed to hold a large # of rows due to the memory overhead.  Web apps are more impacted than client apps.  It would be reasonable to say that you shouldn't try to load 1000 rows into a DataSet as it'll eat up memory.  Then again you shouldn't really be doing that anyway.  IMHO.

     

    Michael Taylor - 11/13/07

    http://p3net.mvps.org

     

     

    Tuesday, November 13, 2007 3:17 PM
  • Thanks Taylor. Really appreciate the time and effort in clearifying the issue.
    Tuesday, November 13, 2007 4:08 PM