tags:

views:

38

answers:

3

I'm working on basic sql, using C# with binding options and adapters. I have sucessfully added data to my database and can then update with no problems. But when I try to delete some data and then UPDATE it throws an exception:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll Additional information: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.

The code:

private void button4_Click(object sender, EventArgs e)
{
    table1TableAdapter.Update(dataSet1);
}

private void button5_Click(object sender, EventArgs e)
{
    table1BindingSource.RemoveCurrent();
}

Why can't I update my database after removing something from it?

A: 

You're remove code isn't deleting anything from the db. It's removing the binding to the datasource. So when you call Update() on that datasource it's no longer bound to anything.

Joel Coehoorn
ohh so how do I fix it ?
Call your Adapter's Delete function rather than your DataSource's RemoveCurrent()
Joel Coehoorn
Adapter Dont have any Delete or Remove Function :O
A: 

I havent been able to solve the issue yet

Did you use the Add query wizard in the VS Dataset designer to build the queries for your Adapter? If so, you may not have checked the 'Advanced options' / 'Generate Insert, Update, and Delete' checkbox, and therefore you won't have a Delete method.
dsteele
i maded query myself so it shd have all methods.but i cant c any update methd in adapter .............
A: 

Anyone has some solution ?