|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Activate Save button in BindingNavigatorI 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 On Thu, 23 Feb 2006 21:54:50 +0100, "reidarT" <rei***@eivon.no> wrote: I'm new at this myself, but this may help.>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 > 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 |
|||||||||||||||||||||||