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

Posted on 2005-04-08
Medium Priority
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
  • 3
  • 2

Expert Comment

ID: 13739194
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

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

Author Comment

ID: 13777535
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?

Accepted Solution

jong3 earned 200 total points
ID: 13780582
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

ID: 14007491
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

839 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