Saving changes imposed by DataSet to .mdb

Hello,

   I am writing some classes that I will use for a project that I am doing involving the use of msaccess databases. For the most part I have been using the System.Data.OleDB namespace in C#. I can manipulate the databases, but once I am done manipulating them how do I save the changes to the same db or a new db I would have thought that it would be fairly self-explanatory. I have tried searching for the solution. What am I missing

I have attached a link to the preliminary version of the classes if that helps. Thanks a lot!
-http://home.bresnan.net/~bcreavis/Code.doc

-freeskier89 :)


Answer this question

Saving changes imposed by DataSet to .mdb

  • Anatoly Stefanyuk

    After a first glance, the problem seems to be in the Save method. Remove the line Data.AcceptChanges, because this will set the RowState of each row to unmodified. The DataAdapter.Update method uses the RowState to check which rows need to be updated/deleted/inserted into the database.

  • razvantim

    Thanks for the reply, but that doesn't seem to work. I am using the classes like this:

    Database db1 = new Database("Users.mdb", "test");

    Table userInfo = db1.GetTable("UserInfo");

    string[] Columns = userInfo.GetColumnNames();

    //Trace is a function that will show a messagebox containing all of the elements of the array

    Trace(Columns);

    userInfo.AddColumn("AddedColumn_" + new Random().Next(0,100).ToString());

    Columns = userInfo.GetColumnNames();

    Trace(Columns);

    db1.Save();

    db1.CloseConnection();

    The second trace shows the added column, but if I re-enter the application, the added column from the program's first execution does not appear. I got rid of the applychanges line. I also traced db1.Data.Tables[0].Columns and that showed the added column also. What is the deal


  • BillyDunny

    Alright I have read through the thread about .Update() problems, and my guess is that my problem relates to that. That thread seems to refer to people who are using the data components though. I am trying to have this be fully dynamic, therefore I don't run into the dialog box concerning whether or not I want to copy the db to the project directory. Am I missing something in that article If anyone would be kind enough to look into my code in the first post, the getTable and Save methods should be the most relevant.

    Thanks in advance!

    -freeskier89


  • Saving changes imposed by DataSet to .mdb