May 1st, 2010, 06:46 AM
Update Requires A Valid DeleteCommand Issue
I'm pretty new to VB.NET, up until recently I've been an Access developer but sadly there ain't no jobs in it anymore so I'm forced to become a VB.NET developer (to be fair it's about time).
I'm going through a book which is teaching me some basic coding principles of the language. The current section is detailing how to set up a master child form using two tables linked with a foreign key. The master table is displayed as a number of text boxes, and below is a grid with the child table which shows related records to whatever master record you happen to be checking out. At the top of the screen are the default navigation controls that are added with the grid. The master table is named Person and the child table Book. They are linked using a foreign key and have cascade set up on them.
The book informed me of the code required under the save icon on the navigation control so that when it is clicked both tables will be updated as required. It is as follows:
If Validate() Then
'Make sure editing has completed on both master and child tables
'Delete records in child table (Book)
Me.BookTableAdapter.Update(Me.MyDBDataSet.Book.Select("", "", DataViewRowState.Deleted))
'Handle add, update and delete in parent table (Person)
Me.PersonTableAdapter.Update(Me.MyDBDataSet.Person.Select("", "", DataViewRowState.Added Or DataViewRowState.ModifiedCurrent Or DataViewRowState.Deleted))
'Handle add and update in child table (Book)
Me.BookTableAdapter.Update(Me.MyDBDataSet.Book.Select("", "", DataViewRowState.Added Or DataViewRowState.ModifiedCurrent))
Catch ex As Exception
'Display message if error occurs
The notes were added by me so sorry if I used the wrong terminology in them, I'm just learning the ropes. I have double checked that the code matches that shown, so this should in theory work fine. But if I manually delete a record from the Book (child table) grid and then click the Save icon on the navigation bar it comes up with the error "Update Requires A Valid DeleteCommand when passed DataRow collection with deleted rows".
Can anyone please inform me why the hell this is coming up and what code has been missed out of the above statement by the authors of the book (and the location/line where this missed code should be added)? I begin to despair when not even the books I purchase allow me to learn the language.
Can anyone also explain why changes made are not permanently saved to the database? I gather that it's using a "copy" of the data in the database but how do I get the code/form to make changes to the actual underlying database records as well as just the copy? I find this system very unusual, if someone deletes a record in the application why would anyone want this to be just done temporarily?
Thanks for your help, much appreciated.
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!