Removing a Database record - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Removing a Database record

mombawombamombawomba Posts: 30Member
I am working on a simple application that uses a data set. The data set and commands were all generated by Visual Studio 2003. The database is one that I created in Access 2003. Everything works except the DELETE command. My code looks like this:

[code]
private void btnRemoveCust_Click(object sender, System.EventArgs e)
{
// Get the current records position
int rowNumber = this.BindingContext[dataSet11, "Customer"].Position;

// Delete the record
dataSet11.Tables["Customer"].Rows[rowNumber].Delete();

// Accept the change
dataSet11.AcceptChanges();
oleDbDataAdapter1.Update(dataSet11, "Customer");
}
[/code]

The problem is that after I run this handler and look at the table nothing has been removed.

I've been looking all over the internet and can't find anything that will tell me if this will even work. Am I doing it right or is there something I'm missing?

Thanks

Comments

  • weiccoweicco Posts: 950Member
    You shouldn't call AcceptChanges before Update because it sets DataRow.RowState to non-changed state. See what MSDN has to say about DataAdapter.Update method.
  • mombawombamombawomba Posts: 30Member
    I just tried removing the AcceptChanges call and it fixed the problem!
    I thought that the AcceptChanges method did something else.

    Thanks and thanks again
Sign In or Register to comment.