Joeri
Joeri

Reputation: 361

Committing dataset changes to database

I'm working with a dataset that's connected to an sql server and what I'm trying to do is delete multiple rows at once and then saving the changes to the sql server. I've tried it with the code below:

DataRow[] rows = this.computechDataSet.VALHIS.Select("VAL_SRT = '" + this.computechDataSet.V_ALUTA.Rows[this.v_ALUTABindingSource.Position][0].ToString() + "'");
foreach (DataRow row in rows)
{
    row.Delete();
}
this.computechDataSet.VALHIS.AcceptChanges();
this.tableAdapterManager.UpdateAll(this.computechDataSet);

The rows do get deleted from the dataset (Found out by outputting the datatable rowcounts) but the changes aren't saved to my SQL database. I haven't had any problems adding/editing/deleting rows on other tables, except in those cases I performed the actions for one row at a time.

Upvotes: 1

Views: 3385

Answers (2)

Turbot
Turbot

Reputation: 5227

try not explicit loop the data row by issuing following method.

this.computechDataSet.VALHIS.Select("VAL_SRT = '" + this.computechDataSet.V_ALUTA.Rows[this.v_ALUTABindingSource.Position][0].ToString() + "'").Delete();

Upvotes: 0

Damith
Damith

Reputation: 63065

try without AcceptChanges

DataRow[] rows = this.computechDataSet.VALHIS.Select("VAL_SRT = '" + this.computechDataSet.V_ALUTA.Rows[this.v_ALUTABindingSource.Position][0].ToString() + "'");
foreach (DataRow row in rows)
{
    row.Delete();
}
this.tableAdapterManager.UpdateAll(this.computechDataSet);

Upvotes: 2

Related Questions