Results 1 to 6 of 6

Thread: Updating Dataset

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    12

    Updating Dataset

    Hi,
    I'm having a problem updating my dataset. I'm using the following procedure:

    Private Sub updateDB()
    Try
    Me.BindingContext(DataSet11, "Supervisors").EndCurrentEdit()
    Me.OleDbDataAdapter1.Update(DataSet11)
    Catch ex As Exception
    MessageBox.Show("An error has occured!Error: "&ex.Message, _
    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try

    End Sub

    When I run the program I get the following error message when trying to alter a record:
    Update requires a valid update command when passed datarow collection with modified rows.

    Any pointers as to where I'm going wrong or what I need to do would be very much appreciated.

  2. #2
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    In what event are you calling this sub "updateDB"?

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    The data adapter needs you to specify an update command in order for it to update the database with the changes in the dataset. You have probably specified the Select command to get the data, but you need to specify the Update command to update data.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    12

    Unhappy

    I specified the SELECT command in the DataAdapter wizard. I have tried to specify the UPDATE command in code but I am not getting anywhere. I've also tried to use the CommandBuilder with the dataAdapter as the arguement. Nothing seems to be working.

    Still don't quite understand where I'm going wrong. I've followed an example from a book and it states that the code in my first post should be all I need to update the database. Any more pointers??

  5. #5
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    On the last page of the wizard, was there checks next to all the generated commands?

    If you dont have a primary key in your table or you have relationships between tables, the wizard will only generate a select command.

    In previous projects of mine, if you dont actually change any data, I've gotten error meassages when trying to update because theres nothing to update.

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    12
    Thanks, think i've solved it now. It was because the database I was using had relationships. Decided to use the Data Form wizard in the end. Better spend more time studying!

    Thanks everyone.

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