Link to home
Start Free TrialLog in
Avatar of bek
bekFlag for United States of America

asked on

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

Hello.

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];
      ds.Tables["Inventory"].Rows.Remove(rowDel);
      resultDA.Update (ds, "Inventory");
Avatar of jong3
jong3

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

In your case:

ds.AcceptChanges();

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

ASKER

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

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of jong3
jong3

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bek

ASKER

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.