Results 1 to 8 of 8

Thread: How to combine Insert and Updates?

Hybrid View

  1. #1
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to combine Insert and Updates?

    First up, don't ask the same question in multiple threads. If you wanted to shift the discussion from the Database Development forum to the VB.NET forum then you should have asked a moderator to move the thread.

    As to the question, why would you need two Buttons anyway? You just put all your data into a DataTable and call Update on the DataAdapter. That will execute the adapter's InsertCommand on all the DataRows with a RowState of Added and the UpdateCommand on all the DataRpws with a RowState of Modified. One method call, ergo one Button, to save all the data.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Location
    United Kingdom
    Posts
    168

    Re: How to combine Insert and Updates?

    Quote Originally Posted by jmcilhinney
    First up, don't ask the same question in multiple threads. If you wanted to shift the discussion from the Database Development forum to the VB.NET forum then you should have asked a moderator to move the thread.

    As to the question, why would you need two Buttons anyway? You just put all your data into a DataTable and call Update on the DataAdapter. That will execute the adapter's InsertCommand on all the DataRows with a RowState of Added and the UpdateCommand on all the DataRpws with a RowState of Modified. One method call, ergo one Button, to save all the data.
    Sorry about the asking same questions part...next time I will ask a moderator.

    So Ive put both the quoted Insert and Update commands in a single button. but the insert still trying to insert when I am just trying to update the @quantityRequested. The update IS working, but the insert is STILL trying to insert as well, which throws up the error "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index". For @bookingsID parameter.

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