-
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.
-
In what event are you calling this sub "updateDB"?
-
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.
-
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??
-
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.
-
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.