• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

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


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");
  • 3
  • 2
1 Solution
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.
bekAuthor Commented:
But how do I get those changes back to my database?
bekAuthor Commented:
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?
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:


bekAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now