Activate Save button in BindingNavigator

R

reidarT

I have entered a BindingNavigator toolbar in a bound form and can manage to
browse records and I am able to enter data in a new record.
I am ot able to save the data and therefore I have entered the save-button.
How do I code this button to save a new record?
reidarT
 
G

gene kelley

I have entered a BindingNavigator toolbar in a bound form and can manage to
browse records and I am able to enter data in a new record.
I am ot able to save the data and therefore I have entered the save-button.
How do I code this button to save a new record?
reidarT
I'm new at this myself, but this may help.

It depends on how your DataSet was filled. If from a single table (no
joins), a primary key exists, and none of the column names are
deliniated by "[ ]" in the fill SQL statement, the 'automated'
UpdateMethod should work.

Assuming a dataset named MyDataSet, a bindingsource named
MyBindingSoure, a tableadapter named MyTableAdapter and a table named
MyTable, this code would generally work if the above criteria are
satisfied:

Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles btnUpdate.Click
If Me.Validate() = True Then
Me.MyBindingSource.EndEdit()
Me.MyTableAdapter.Update(Me.MyDataSet.MyTable)

Else
'there were validation errors
End If
End Sub

In the above example, the Update statement can throw an exception if
above criteria do not apply telling you that you need a valid Update
Command. I did somthing like this last week with an Access DB. At
first, the update would not work. Turned out that one of the columns
in the DB was named "Size" and appeared in the SQL statement as
[Size]. I renamed the column and the update then worked.

Gene
 

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