none
Table Adapter to change as Sql Table has been changed RRS feed

  • Question

  • Hi all

    I' am studing to use Table Adapter fro a sql table

    The problem is the following

    I create a Database (TESTDB) with just one table (TABLE1) using SSMS

    In visual studio i have a Form with several Textbox

    Then form Data Source I add a Dataset  and then I choose to add TABLE1, so a I get a tableadapter for TABLE1

    I don't drag and drop TABLE1 in dataset designer but I bind each textbox manually using DataBinding Property Text for each textBox.

    Everthing works perfectly

    Now....I want to change TABLE1 with SSMS, Changing columns

    I go back to visualstudio and try to change delete the old TAbleAdapter and add a new one !

    But, this is the proble,   nothing works anymore.

    SO the question is.

    Which is the right procedure to delete a Table from a Dataset using DataSet Designer ? 

    I

    Wednesday, December 13, 2017 7:31 PM

Answers

  • Here is my thoughts on which way to go. I've listed several examples I've done on the topic of master/detail where two do customer/order model, one simply shows how to setup relationships between three tables (a bit more than master detail) while the last shows how to work with Entity Framework with a single table to get a taste of what to expect.

    Which one to pick? I'd say example the samples below, study them online or download and actually try them. Decide which one fits your skill level and go from there.

    If I were to dictate which one it would be Entity Framework as it's easy to work with but only after spending time to learn it, otherwise it can be difficult to get started with.

    So my second choice is using a manage data provider like all but one of the samples show. There is more coding involved yet you are in complete control of everything. For years this was my method of working with databases (mainly SQL-Server) until three years ago when we moved to Entity Framework.

    Lastly, if you end up looking at the samples listed below and have questions, come back and ask me here. During the day I'm less active then early or mid evening. I will not lie to you, there will be challenges but if you follow my samples I believe you will be much, much better off than using TableAdapters. 

    The following shows how relation data is setup into a master/master-detail/detail (kind of like customer/orders/order-details), what you can learn from this is how relations are setup, that's up using the manage data provider for SQL-Server.
    https://code.msdn.microsoft.com/-Detail-for-ListBoxs-and-d896b5ed?redir=0

    The following shows how to do a simple master/detail, customers as master, orders as details. I show adding, updating and removal operations but not finding and filter which are easy to add in.
    https://code.msdn.microsoft.com/Windows-forms-detail-view-89372f21?redir=0

    To learn about filtering concepts
    https://code.msdn.microsoft.com/BindingSource-Find-and-08e48b45?redir=0

    The above are all using the manage data provider for SQL-Server while the following (which is not master detail) shows the difference of working with Entiity Framework. I show adding, editing, removal operations and filtering
    https://code.msdn.microsoft.com/Entity-Framework-6-for-06edd4a8?redir=0


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Claudio111 Thursday, December 14, 2017 8:42 AM
    Thursday, December 14, 2017 12:42 AM
    Moderator
  • Hi Claudio111,

    According to your description, you want to change table1 with SSMS, and change columns or other, now you delete the old tableadapter and add new one tableadapter. I think you could need to delete all at the bottom of the form(like dataset, TableBindingSource, TableAdapter) and drag new table in the dataset, and rebind again, then it will work fine.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Claudio111 Thursday, December 14, 2017 8:49 AM
    Thursday, December 14, 2017 7:57 AM
    Moderator

All replies

  • Here are the steps

    1. Do what you have done, setup a data source.
    2. Now back in SSMS in the same table, add a field.
    3. Back in Visual Studio, select the Data Source window
    4. Right click on the DataSet
    5. Select "Configure"
    6. Select OK.
    7. The new field is generated
    8. Done for configuration.

    Back to the form, the hard part, you need to comment out any code referencing the TableAdapter then delete the TableAdapter and associated component then add them back in. If the new implementation of the generated code from the bullet-ed list have the same properties (excluding the new field) then you would be good to go yet many times that is not the case hence why I dislike this form of working with data.

    If this was Entity Framework you would do similar steps to the billeted list and be done.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Wednesday, December 13, 2017 8:52 PM
    Moderator
  • So Kared, what do you suggest for working with data. ? I know you dislike Tableadapter. I have to develop a business application (customer, order etc)
    Wednesday, December 13, 2017 10:44 PM
  • Here is my thoughts on which way to go. I've listed several examples I've done on the topic of master/detail where two do customer/order model, one simply shows how to setup relationships between three tables (a bit more than master detail) while the last shows how to work with Entity Framework with a single table to get a taste of what to expect.

    Which one to pick? I'd say example the samples below, study them online or download and actually try them. Decide which one fits your skill level and go from there.

    If I were to dictate which one it would be Entity Framework as it's easy to work with but only after spending time to learn it, otherwise it can be difficult to get started with.

    So my second choice is using a manage data provider like all but one of the samples show. There is more coding involved yet you are in complete control of everything. For years this was my method of working with databases (mainly SQL-Server) until three years ago when we moved to Entity Framework.

    Lastly, if you end up looking at the samples listed below and have questions, come back and ask me here. During the day I'm less active then early or mid evening. I will not lie to you, there will be challenges but if you follow my samples I believe you will be much, much better off than using TableAdapters. 

    The following shows how relation data is setup into a master/master-detail/detail (kind of like customer/orders/order-details), what you can learn from this is how relations are setup, that's up using the manage data provider for SQL-Server.
    https://code.msdn.microsoft.com/-Detail-for-ListBoxs-and-d896b5ed?redir=0

    The following shows how to do a simple master/detail, customers as master, orders as details. I show adding, updating and removal operations but not finding and filter which are easy to add in.
    https://code.msdn.microsoft.com/Windows-forms-detail-view-89372f21?redir=0

    To learn about filtering concepts
    https://code.msdn.microsoft.com/BindingSource-Find-and-08e48b45?redir=0

    The above are all using the manage data provider for SQL-Server while the following (which is not master detail) shows the difference of working with Entiity Framework. I show adding, editing, removal operations and filtering
    https://code.msdn.microsoft.com/Entity-Framework-6-for-06edd4a8?redir=0


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Claudio111 Thursday, December 14, 2017 8:42 AM
    Thursday, December 14, 2017 12:42 AM
    Moderator
  • Hi Claudio111,

    According to your description, you want to change table1 with SSMS, and change columns or other, now you delete the old tableadapter and add new one tableadapter. I think you could need to delete all at the bottom of the form(like dataset, TableBindingSource, TableAdapter) and drag new table in the dataset, and rebind again, then it will work fine.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Claudio111 Thursday, December 14, 2017 8:49 AM
    Thursday, December 14, 2017 7:57 AM
    Moderator
  • Thanks Karen

    My thoughts is : In MSDN you can find a lot of documentation but NO  a very goood Tutorial - only separated pieces and it is very difficult to organize all the documentation in the mind.

    I think your help will solve the problem

    Bye 

    Claudio

    Thursday, December 14, 2017 8:46 AM
  • Hi Cherry

    it seems this is the only way unfortunatly. 

    I dont know if it  is good idea to work with Table Adapter if the Database is not completed, but even a in this case if in the future I have to change something to the application i will get a lot of problems to do modifications.

    Thanks

    Claudio

    Thursday, December 14, 2017 8:49 AM