Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BindingNavigator won't save record

Status
Not open for further replies.

artyk

Programmer
Apr 5, 2006
163
US
I'm pretty new to VB.NET and I'm trying to create what should be a simple Add/Edit/Save form using a BindingNavigator, BindingSource, and TableAdapter. I dragged the table from the Data Sources Explorer and VB.Net has created the controls (textboxes, comboboxes) that are needed, the BindingNavigator, and also the code that is supposed to work. However when I run the app, click on the "add new" button and then the "save" button, the record never appears in the table. The odd thing is that if I click "add new" and then "save" without entering any data I get an error saying that null values are not allowed, which would be correct. If I add values to the table by hand it has no problem navigating through them, but it will not add a new record or delete an existing record. I'm sure the problem is in the BindingSource or TableAdapter, but I'm lost as to where to go from there. Any suggestions would be well appreciated. Thanks.
 
Nevermind. It seems to work when you modify the app.config file and include the full path to the database file instead of "system path" or whatever the default is. I'm not sure why if you specifically include it in the app it still has trouble editing it, but it does.
 
It still won't delete or edit existing records, but it will add records now. Any ideas as to what I could try? Thanks.
 
BTW, here is the code I'm currently using for the save operation:

Code:
Try
   Me.Validate()
   Me.SpecialtyBindingSource.EndEdit()
   Me.SpecialtyTableAdapter.Update _(Me.CaseInputDataSet.Specialty)

   MsgBox("Update Successful", MsgBoxStyle.OkOnly)
Catch ex as Exception
   MsgBox("Update Failed",MsgBoxStyle.Critical)
End Try

The first time I try the edit of an existing record it says "Update Successful". And when I try to update a record that has not been changed it says "Update Failed", so it is seeing the difference between a changed and unchanged record.

I've also tried:

Code:
Me.SpecialtyTableAdapter.UpdateQuery(txtSetupSpecID.Text, _
  txtSetupSpecDesc.Text)

Where UpdateQuery is:

Code:
UPDATE Specialty
SET SpecialtyID = @Param1, Specialty = @Param2

but that changed every record in the table with the updated value. Thanks again.
 
One more thing I forgot to include. When I set a breakpoint the error I get on the sub procedure is:

"Update requires a valid UpdateCommand when passed collection with modified rows."

The "general help" that is provided with this error isn't much help. It basically says the same thing in different words and mentions some things that have to do with graphics.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top