Using Data Readers In Applications with XSD Typed Datasets RRS feed

  • Question

  • I am building a web application and using Typed Datasets as my data access layer.  The Typed Dataset select methods appear to return TableAdapters.  I now want to create and use a data reader.  How do I create a data reader from a Typed Dataset or are the two mutually exclusive?


    Pardon me if the question seems to make no sense.  I'm learning the concepts of using Typed Datasets.



    Friday, November 2, 2007 4:09 PM

All replies

  • Hi,

    It's possible to use data readers to fill datasets (and also typed datasets). I think that the dataadapter itself uses a datareader to fill the dataset from database.

    You can do this by creating manually a datarow, fill it with data from each row returned by the datareader, then add it to the table.

    You can also automate this, but you will find that ure juste rewriting the dataadapter code. In this case you must consider these points :

    - You have to map a datatable column with the column name returned by the query. That means that a datatable column name can be different from the column name in the query.

    - To update the database u cannot benefit from the dataadapter features and u must implement row by row update/insert/delete.

    - etc...


    So, I think that using datareader with datasets is "useless". Personally I use always datareaders but i fill data in objects (I don't use datasets).





    Friday, November 2, 2007 5:11 PM
  • Thanks for the reply.


    Actualy I was wanting to create a method to populate a data reader from within my Typed Dataset.  For example, I already have a GetProducts method in my Typed Dataset that returns a TableAdapter.  Now I want to create an almost identical method that returns a DataReader.  However, the designer won't allow me to do this.


    I also suspect I want to do this in an external VB file with a partial class, so future changes with the designer won't wipe out my DataReader method.


    Thanks again

    Friday, November 2, 2007 5:46 PM
  • OK, call me crazy, but why in the world would you want a method in your DataSet to return a TableAdapter or a DataReader? What is the purpose of doing this?

    Monday, November 5, 2007 1:42 AM
  • First, I did figure it out.


    Second, I'm using typed datasets, hence they contain methods that return data.  The designer creates methods that return TableAdapters.

    Monday, November 5, 2007 3:10 PM
  • Really? Could you post this generated code? The designer did not generate any method in my Typed DataSets for returning a TableAdapter (and I wouldn't want it to anyway) ... so I was just curious how/why yours did that.


    The problem with TableAdapters is that it couples your DataSet too tightly to your database. IMHO, a DataSet should know nothing about where it gets it's data. A DataAdapter fills the DataSet with data. Period.

    Tuesday, November 6, 2007 12:18 AM