Results 1 to 4 of 4

Thread: [RESOLVED] VS 2013 - Updating TableAdapterManager Raises An Error

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Posts
    21

    Resolved [RESOLVED] VS 2013 - Updating TableAdapterManager Raises An Error

    Hello, Good Day

    I'm hoping someone here can help me with this, I'm using data sources and for awhile now I've been looking into why i can't update the database with new data and this is as far as I've gotten.

    When i click save on the auto-generated binding navigator this code runs,


    Code:
           Me.Validate()
            Me.Table1BindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.NorthwindDataSet)

    and on the last line instead of getting a successful update, i get this.


    An unhandled exception of type 'System.InvalidOperationException' occurred in UpdateSingleTableWalkthrough.exe

    Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.



    After a lot of online searching, i found my way to editing the dataset in the designer. There i noticed the updatecommand is missing

    Name:  Screenshot (122).png
Views: 2751
Size:  11.9 KB


    so i attempted to add one and this is where i'm stumped.

    Name:  Screenshot (125).jpg
Views: 2675
Size:  26.7 KB

    I've tried various things that i hoped would work but they've all ended in the database not being updated. I really would appreciate it if anyone here could grant me the use of their knowledge.

    Oh and i'm using the Microsoft Access Database Engine as my provider, if that helps.
    Last edited by WestFiasco; Oct 29th, 2014 at 09:07 AM. Reason: Added Code Tags

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: VS 2013 - Updating TableAdapterManager Raises An Error

    Firstly, some house-keeping. To be precise, you're not updating a table adapter. The table adapter is updating the database. I think that it's important to think of these things in the correct way to avoid confusion, especially when things go wrong. If you don't look at a problem the right way then solving it can be more difficult.

    Also, when you post code snippets, please use formatting tags to make the code easy to read. Use:

    [code]your code here[/code]

    if you need to add extra formatting, e.g. bold or underline, and use:

    [highlight=vb.net]your code here[/highlight]

    to get full syntax highlighting. Both maintain indenting, which is the most critical thing for readability of code. There's a button for each on the editor tool bar or you can type them yourself. If you use button for the [highlight] tag, make sure that you provide the correct option to provide the correct highlighting.

    As for the issue, I see that your table adapter has a SelectCommand and InsertCommand but no UpdateCommand or DeleteCommand. That is almost certainly caused by your database table not having a primary key. In order to update or delete a record, you must be able to identify it. Without a primary key, that's not possible. It's very rare that a table not having a PK is justified and certainly not in this case. Fix your database and run the configuration wizard from the Data Sources window again and your missing commands will be created.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Posts
    21

    Re: VS 2013 - Updating TableAdapterManager Raises An Error

    Thank you so much, during school when i had a project using databases in vb6 my teacher told me to delete the primary key. That's what i did with what i'm doing now and ended up stuck, strangely enough when trying to fix whatever was wrong i saw it mentioned online that the primary key was necessary. I did re-add it after seeing that, but i assumed that once i ran the program again all would be automatically fixed. Thanks again, for explaining the use of the primary key, what i was missing and proper forum etiquette.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: VS 2013 - Updating TableAdapterManager Raises An Error

    Quote Originally Posted by WestFiasco View Post
    Thank you so much, during school when i had a project using databases in vb6 my teacher told me to delete the primary key. That's what i did with what i'm doing now and ended up stuck, strangely enough when trying to fix whatever was wrong i saw it mentioned online that the primary key was necessary. I did re-add it after seeing that, but i assumed that once i ran the program again all would be automatically fixed. Thanks again, for explaining the use of the primary key, what i was missing and proper forum etiquette.
    To be precise, a primary key isn't actually necessary. If you want to be able to act upon a specific record then you have to be able to identify that record, which means that it must have some unique feature. That's going to be a value in one column or the combination of values in more than one column. It might be part of the data itself or it might be a random or sequential value that's generated specifically for the purpose, known as a surrogate key. As long as it's unique, that's all that's actually required.

    Making the column or columns containing those distinct values the primary key for the table is a formalisation of the unique state of the data they contain. That formalisation allows you to do some extra, useful things, e.g. the database will generally making searching the primary key faster than searching other columns. Many automated tools, including the SQL generation in the VS Data Source wizard, require that formal declaration of the primary key in order to generate UPDATE and DELETE statements, which require unique identification of each record. You could forgo the primary key and write those statements yourself but why would you?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width