none
C# How to save changes in Dataset to MDB file RRS feed

  • Question

  •  I am making an inventory program utilizing an exsisting MS Access Database using C# as a frontend.  I have had no problem importing the data, and displaying it accordingly.  Adding an modifying seem to work, but the changes in data are not reflected in the external database (so when I close the program the changes to the database are not saved.  How can I go about saving these changes? (I am new to data access in c# so even if its a simple step i probably overlooked it)

     

    Heres a sample code i just made that still has the problem (the form displays the inserted rows and updated rows fine.. but when you close the program and reopen it, there are still no entries. The Dataset and TableAdapters were all made automatically (since i added a DataGridView to the form to watch the output)

     

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent();

    }

    private void button1_Click(object sender, EventArgs e)

    {

    this.testTableAdapter.Insert("Greg", "Smith");

    this.testTableAdapter.Fill(database1DataSet.Test);

    }

    private void Form1_Load(object sender, EventArgs e)

    {

    // TODO: This line of code loads data into the 'database1DataSet.Test' table. You can move, or remove it, as needed.

    this.testTableAdapter.Fill(this.database1DataSet.Test);

    }

    private void button2_Click(object sender, EventArgs e)

    {

    database1DataSet.Test[0].FName = "Melissa";

    database1DataSet.Test[0].LName = "Donald";

    this.Validate();

    testBindingSource.EndEdit();

    testTableAdapter.Update(database1DataSet.Test);

    testTableAdapter.Fill(database1DataSet.Test);

    }

    }

     

    thanks.

    Greg

    Tuesday, August 14, 2007 8:19 PM

Answers

  • Be sure that in your project, if you have the database attached within your solution that you are not overwriting it. So select the MS Access database in your solution explorer and make sure that its "Copy to output" is set to "Do not copy", then manually copy over the MS Access database file to the project\bin\debug folder then run the application.

     

    What happens now?

     

    Thursday, August 16, 2007 3:37 AM

All replies

  • Be sure that in your project, if you have the database attached within your solution that you are not overwriting it. So select the MS Access database in your solution explorer and make sure that its "Copy to output" is set to "Do not copy", then manually copy over the MS Access database file to the project\bin\debug folder then run the application.

     

    What happens now?

     

    Thursday, August 16, 2007 3:37 AM
  • just before you posted this I realized what was going on, because I had my Access database open, and saw that all the information was infact making it to the database, but was overwritten when it was built the next time.

    Thanks for the answer, regaurdless that I already realized my mistake, its nice to know how useful this forum is.

    Greg
    Thursday, August 16, 2007 3:41 AM
  •  

    no worries, glad you and I could help you
    Thursday, August 16, 2007 3:50 AM
  • I love you, thx for helping. I had the same problem !!!!!!!!!! kiss xD
    Saturday, May 23, 2009 10:31 PM