Start New Discussion within our Software Development Community

Hi to all

I used standard item in binding navigator such as add and save button. How can I modified the code for add records button like if the user press this button then insert to my database and for the save button to save in my database. I already tried to add and save but it was not add and save to my database.

Thanks

just try below code in your add button to add record using binding navigator
note : suppose you have datasource nam ds,tablename is cTablename

myCurrencyManager = (CurrencyManager)FormName.BindingContext[ds, cTableName];
            myCurrencyManager.Position = 0;
            bs = new BindingSource();
            bs.DataSource = ds.Tables[cTableName];
            bindingNavigator1.BindingSource = bs;
            if (bs.Count == 0)
            {
                lInsert = true;
                myCurrencyManager.AddNew();
                myCurrencyManager.EndCurrentEdit();
            }

For save button add this code to click event:

Me.Validate()
Me.BindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DataSet)
Me.Close()

For add button add this code to click event:

BindingSource.AddNew()

This article has been dead for over six months. Start a new discussion instead.