How to update my database table from my grid?  (Almost done--just need a little help.)

Posted on 2005-04-08
Last Modified: 2010-04-16

I am trying to cascade my delete from the dataset back to the database.  Here's my code.  What am I leaving out?  The row disappears from the datagrid, but it's still in the database.

(Don't worry about the hardocded '2'.  That's just there to simply the problem.

Thanks in advance!

      string strSQLDelete = "delete from Inventory where ID= 2";
      OleDbCommand cmdDelete = new OleDbCommand (strSQLDelete, dbConn);
      resultDA.DeleteCommand = cmdDelete;
      DataRow rowDel = ds.Tables ["Inventory"].Rows[1];
      resultDA.Update (ds, "Inventory");
Question by:bek
    LVL 2

    Expert Comment

    Try doing a Dataset.AcceptChanges() right before the update command.

    In your case:


    This function should finalize the deleted rows, and remove it completely from the dataset.

    Author Comment

    But how do I get those changes back to my database?

    Author Comment

    I tried adding ds.AcceptChanges() where you said.  No errors, but it didn't remove the row from my database.

    Any idea what's wrong?
    LVL 2

    Accepted Solution

    Yes.  Sorry for the delay in answering your question.

    The AcceptChanges() will only update your dataset, you will still need to run the Update command on your database.

    Your dataset is basically a local copy of the data from your database.  When you edit the dataset, flags are set to identify what was done to it.  By using the AcceptChanges command, it will finalize your changes, and allow the Update command to execute the way you expect it to.

    The Update command will run Insert/Update/Delete accordingly to what you have done with your dataset.

    YOU will need to specify the UpdateCommand parameter to indicate to the database what is going on.  Read the following for more information on the DataAdapter.Update command:

    Author Comment

    I never really got an answer, but figured it out myself.  However, if you wish to award the points to jong3, I have no problem with that because he was trying to help me.

    We really need the option to delete questions on our own.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now