Home All Groups Group Topic Archive Search About

Activate Save button in BindingNavigator

Author
23 Feb 2006 8:54 PM
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

Author
25 Feb 2006 12:55 AM
gene kelley
On Thu, 23 Feb 2006 21:54:50 +0100, "reidarT" <rei***@eivon.no> wrote:

>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