Saving changes to a database

G

Guest

I'm working on an application using VB .Net 2005 and MS Access 2003 for the
database. The table I'm trying to update has a key field. When I click the
Save Button the update seems to work in the dataset, but the database is not
updated. The code I'm using for the btnSave is:

Private Sub btnSave_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSave.Click

'saves adds and edits to database
If bChange = False Then
MsgBox("Nothing To Save", MsgBoxStyle.OkOnly, "Test!!!!")
Else
Me.Validate()
Me.TblCompanyBindingSource.EndEdit()
Me.TblCompanyTableAdapter.Update(Me.DsCompData.tblCoompany)
bChange = False
End If

Me.DisplayPosition() 'reset record location
Me.setMaintenceButtons(True)

End Sub

Any suggestiona dn help is greatly appreciated!!!!
 
C

Cor Ligthert [MVP]

Tony,

Are you sure that this is your code. Because it seems if you are using two
different tables.

Cor
 
G

gene kelley

I'm working on an application using VB .Net 2005 and MS Access 2003 for the
database. The table I'm trying to update has a key field. When I click the
Save Button the update seems to work in the dataset, but the database is not
updated. The code I'm using for the btnSave is:

Private Sub btnSave_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSave.Click

'saves adds and edits to database
If bChange = False Then
MsgBox("Nothing To Save", MsgBoxStyle.OkOnly, "Test!!!!")
Else
Me.Validate()
Me.TblCompanyBindingSource.EndEdit()
Me.TblCompanyTableAdapter.Update(Me.DsCompData.tblCoompany)
bChange = False
End If

Me.DisplayPosition() 'reset record location
Me.setMaintenceButtons(True)

End Sub

Any suggestiona dn help is greatly appreciated!!!!

In debug mode? Select the DB and change the "Copy to Output
Dirirectory" property to something else if it is currently set to
'Copy Always'

Gene
 
G

Guest

I see where tblCoompany was misspelled. Should have been tblCompany. It is
correct in the application. Thanks. Other suggestions??
 
G

Guest

What is bchange and when is it getting changed? Are you sure the
tableadapter is firing the update event?
 
G

Guest

I have a procedure that checks to see if the value in any of the text boxes
or combo box has changed = bchange

The program crashes at the TableAdapter.Update line. This error appears:

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

Guest

Sounds like you need an update statement - did you remove it at some point
from your data adapter? If you use a wizard to automatically add one, ensure
part of the update statement doesn't try and update your key field.
 
G

Guest

Thank you.
--
Tony


ewok66 said:
Sounds like you need an update statement - did you remove it at some point
from your data adapter? If you use a wizard to automatically add one, ensure
part of the update statement doesn't try and update your key field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top