locked
How to add a TableAdapter without creating a new table? RRS feed

  • Question

  • Hi,

    I have a typed dataset that I created using the Dataset Designer. I need to use TableAdapters to fill the tables in the dataset. But there's a problem: if I try to create a new TableAdapter, the wizard automatically creates a new table and adds it to the dataset, along with the TableAdapter.

    Here's my question: how can I add a TableAdapter to an existing table? I don't want the wizard to create new tables, just a TableAdapter. I want the adapters be assigned to the tables I already have in the dataset.

    Please help!

    Thanks in advance.

    Regards,

    Abdul

    • Moved by Mike Feng Monday, December 3, 2012 10:05 AM (From:.NET Base Class Library)
    Sunday, December 2, 2012 2:59 PM

Answers

  • I don't think you can.

    My blog: blog.jessehouwing.nl

    • Marked as answer by Abdul A. Ali Tuesday, December 4, 2012 2:37 PM
    Monday, December 3, 2012 4:46 PM
  • Hi Abdul,

    I have tested on my side, and I am not be able to add a tableadapter without creating a datatable. Could you please let me know why you don’t create a new Dataset instead of using the existing one?

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Abdul A. Ali Tuesday, December 4, 2012 2:37 PM
    Tuesday, December 4, 2012 8:12 AM

All replies

  • Rightclick the table, add a new query or stored procedure. It will put the new statements in the existing TableAdapter. It won't create a 2nd TableAdapter, but it will update the existing one.

    You can't have multiple adapters in the same table through the designer.


    My blog: blog.jessehouwing.nl

    Sunday, December 2, 2012 10:19 PM
  • Hi Jesse. Thanks for replying.

    I did what you told me. I right-clicked on the DataTable,  but the add>Query option is disabled (greyed out). I could right-click on the DataSet Designer, or drag a Query object from the toolbox, but there are two problems with that: there's no way to attach the query to a DataTable (it becomes a stand-alone function inside the DataSet class), and it only allows you to return a single value, not rows. Please look at the illustrations below:

    1) If I right-click on the DataTable, the options to add a TableAdapter and a Query are disabled:

    2) You can right-click on the DataSet designer, and you'll see the options to add a TableAdapter or a Query, but the problem is that the TableAdapter will create a new table, and the query will have no table assigned to it. It will become a separate function inside the DataSet.

    3) If you choose to right-click on the DataSet Designer and add a query, the query does not allow you to return rows, it only enables you to return a single scalar value:


    I hope these illustrations explain my problem. Please help me!

    Regards,

    Abdul


    Monday, December 3, 2012 4:05 AM
  • What type of database and Visual Studio Version are you using? When I drag a table from SQL Server directly onto my dataset, I get a table, with a pre-made table adapter. The adapter has a fill and a GetData method.

    That table adapter has a Add Query option:

    Which results in this wizard:


    My blog: blog.jessehouwing.nl

    Monday, December 3, 2012 7:13 AM
  • Hi Jesse,

    I'm using Visual Studio 2010, but my scenario is different from what you're doing in the illustration above. I can drag a table from the server explorer, and I'll get a DataTable with a configured TableAdapter too, but that's no the case. I have been given an XSD file that contains the schema of a typed dataset. The dataset contains tables but not the adapters to fill them. I imported the XSD file to visual studio, and it automatically generated a typed dataset for me. So, I already have all the tables I need in the dataset, and I don't need to add any more tables, or delete existing ones. I just want to create TableAdapters that fill the tables I already have in my dataset.

    Can you please tell me how can I do that?

    Regards,

    Abdul


    Monday, December 3, 2012 11:25 AM
  • I don't think you can.

    My blog: blog.jessehouwing.nl

    • Marked as answer by Abdul A. Ali Tuesday, December 4, 2012 2:37 PM
    Monday, December 3, 2012 4:46 PM
  • Hi Abdul,

    I have tested on my side, and I am not be able to add a tableadapter without creating a datatable. Could you please let me know why you don’t create a new Dataset instead of using the existing one?

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Abdul A. Ali Tuesday, December 4, 2012 2:37 PM
    Tuesday, December 4, 2012 8:12 AM
  • He Alexander,

    I wanted to use the old dataset because it was given to me like that, and I didn't want to recreate everything from scratch. But now that I know I can't add a TableAdapter without creating a new table, I've requested for a revised dataset which has TableAdapters associated with the tables.

    Thanks for the response!

    Regards,

    Abdul

    Tuesday, December 4, 2012 2:36 PM