none
Add tableadapter to typed dataset after table has been created RRS feed

  • Question

  • I've created a dataset which contains all of the data that I need for my application. I'm now creating the tables in the database and now want to add table adapters to my dataset. There doesn't seem to be any way to do it from the designer. When I right click on a table in the dataset I can only add:
    Relation
    Key
    Column

    Wednesday, June 10, 2009 2:12 PM

Answers

  • Does your DataSet and the DataTables in it look the same as your Database or not? If they are pretty much a 1-1 mapping, what I would do is the following:
    1) open up the Server Explorer
    2) add a DataConnection to where you have your database defined
    3) Drag all the tables from the Server Explorer to the DataSet design surface.

    By doing this, it will create the DataTables and also TableAdapters for each DataTable.
    The following msdn article describes the experience more
    http://msdn.microsoft.com/en-us/library/6sb6kb28(VS.80).aspx

    When you try to generate TableAdapters it appears you can't do it unless you want to generate a DataTable with it. If you right click on the design surface when its not on a DataTable it will give you an option to create a DataTable.

    Now what you could do is just write your own Adapters to connect to your specific DataSet. This may be beneifical if there are places where there isn't an exact 1-1 mapping between the database and your DataSet model. If you would like to do this. I would follow the documentation here that describes how to do this.

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

    Thanks,
    Chris Robinson
    Program Manager - DataSet


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, June 10, 2009 3:05 PM

All replies

  • Does your DataSet and the DataTables in it look the same as your Database or not? If they are pretty much a 1-1 mapping, what I would do is the following:
    1) open up the Server Explorer
    2) add a DataConnection to where you have your database defined
    3) Drag all the tables from the Server Explorer to the DataSet design surface.

    By doing this, it will create the DataTables and also TableAdapters for each DataTable.
    The following msdn article describes the experience more
    http://msdn.microsoft.com/en-us/library/6sb6kb28(VS.80).aspx

    When you try to generate TableAdapters it appears you can't do it unless you want to generate a DataTable with it. If you right click on the design surface when its not on a DataTable it will give you an option to create a DataTable.

    Now what you could do is just write your own Adapters to connect to your specific DataSet. This may be beneifical if there are places where there isn't an exact 1-1 mapping between the database and your DataSet model. If you would like to do this. I would follow the documentation here that describes how to do this.

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

    Thanks,
    Chris Robinson
    Program Manager - DataSet


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, June 10, 2009 3:05 PM
  • There isn't a 1-1 mapping, also, we use stored procedures for all access to the database. I don't understand why you can't add a table adapter to a table in your dataset. I'm weary about using datasets now. I spent a lot of time "documenting" the data structure I want to use using datasets, and now they are basically useless.

    Wednesday, June 10, 2009 3:22 PM
  • Okay so how about trying this instead.

    Create a new DataSet project Item, now right click on the surfaces and Add->Query. When you do this you will select a connection string, after this you have the option to "Use existing store procedures", click that and click next. Then this will create  stored procedure query for you. Then you will have to write code to use the stored procedure to fill the data into a DataSet and do updates as well. You will need to create a query for each of the stored procedures you have. Now alternatively you can also create a table adatper and specify the Select Update, Insert and Delete stored procedures that you have for each table. This will create a new DataTable. But you can use these table adatpers to fill data into a different table. You will have to specify how this tableadatper maps to the DataTable you have made though.

    http://msdn.microsoft.com/en-us/library/27b34c50(VS.80).aspx

    Otherwise you have to code the DataAdapters to put data in and set data out.
    http://msdn.microsoft.com/en-us/library/bh8kx08z(VS.80).aspx

    There is no magic that can be done to map columns together if they don't match up exactly. You will need to review the documentation on msdn to do this for your application. All I can offer is guidance on how to do this. Since things don't match up exactly 1-1 and that is the scenario the designers aim at you will need to do some more work at your datalayer to achieve this.

    Now that said I would look at the requirements of your application. Do you need to put things into a DataSet? DataSet is essentially an inmemory database. Can you always connect to a database? I don't know what version of the .net Framework you are on but if you can always make a database connection, and you are on .net Framework 3.5 Sp1 then you could use Linq to Sql or Entity Framework instead. These allow you to define a conceptual layer and then connect it to a physical layer in Sql Server.

    Thanks
    Chris Robinson
    Program Manager - DataSet


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, June 10, 2009 6:06 PM
  • Can you point me to docs on Entity Framework? Is that something like NHibernate?
    I've been extremely weary of LINQ so far.
    Wednesday, June 10, 2009 6:56 PM
  • Below is a link to an overview of Entity Framework.

    http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx


    Thanks
    Chris
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, June 10, 2009 8:03 PM