Help with C#, bindingNavigator not afecting actual databse records

Started by
0 comments, last by Nik02 14 years, 1 month ago
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;
    }

   
}


Advertisement
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.

Niko Suni

This topic is closed to new replies.

Advertisement