Sign in to follow this  

Help with C#, bindingNavigator not afecting actual databse records

This topic is 2845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I did what I was supposed to when doing data bindings to the bindingNavigator and dataGridView. Everything seems to be fine, bindingNavigator is displaying the records added and deleted from the datagridview. However bindingNavigator doesn't seem to be affecting my Acces database because everytime I restart the application, all records from the database apear all over again. I tried a lot of things but I got the same place. Is there something else I need to do? Anyways, here's the code to make things clearer.
public partial class Form1 : Form
{
    //Ole declarations
    public OleDbConnection olecon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Luis.accdb; Persist Security Info=False;");
    public OleDbDataAdapter dataAdapter1;
    public DataSet dataset1 = new DataSet();

    public Form1()
    {
        InitializeComponent();

        //Ole connections and bidings
        dataAdapter1 =
        new OleDbDataAdapter(new OleDbCommand("select * from Conrehabit order by id", olecon));
        dataAdapter1.Fill(dataset1, "Conrehabit");
            
        bindingSource1.DataSource = dataset1;
        bindingSource1.DataMember = "Conrehabit";

        bindingNavigator1.BindingSource = bindingSource1;
        dataGridView1.DataSource = bindingSource1;
    }

   
}


Share this post


Link to post
Share on other sites
When you call Fill, the data is only loaded to memory in the form of the dataset - not automatically bound to the original source.

In order to commit the changes of your dataset, you can call the adapter's Update method. This is commonly triggered by different events such as when the user's row focus changes or when the user presses a Update/Save/Delete record button.

The dataset itself keeps track of the modifications on its data.

Share this post


Link to post
Share on other sites

This topic is 2845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this