PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Re: Concurrency violation on Update DeleteCommand

Reply

Re: Concurrency violation on Update DeleteCommand

 
Thread Tools Rate Thread
Old 08-07-2003, 08:00 AM   #1
Gec
Guest
 
Posts: n/a
Default Re: Concurrency violation on Update DeleteCommand


Hi,

I would like to delete row from dataSet and with function call
DataAdapter.Update delete it from datasource(database) as well.

I really don't know why it throws "Concurrency violation".
The previously added row with DataAdapter.Update is successful.
The record exist in the dataSet and database.

Best regards,
Gec


"Eli Markov" <nada@nada.nada> wrote in message
news:75e801c3448c$d1433a20$a401280a@phx.gbl...
> Hi,
>
>
>
> It depends on what kind of delete you do. If you call
> someRow.Delete(), the RowState of this row is set
> RowState.Deleted, and the DataAdapter will call the Delete
> statement. If the return is 0 (nothing has been deleted)
> exception is thrown.
>
>
>
> So, If you want to cancel the addition of the row, you
> have to call DataTable.Rows.Remove(DataRow).
>
> To check which rows are added, you can iterate through the
> rows with the RowState.Added using:
>
> DataTable.DefaultView.RowStateFilter =
> DataViewRowState.Added;
>
>
> while(DataTable.DefaultView.Count > 0)
> DataTable.Rows.Remove(DataTable.DefaultView[0].Row);
>
> Eli.
>
> >-----Original Message-----
> >I'm using dataGrid connected to the dataSet and dataSet

> connected to the
> >table through dataAdapter.
> >
> >dAdap = new SqlCeDataAdapter( "SELECT field1, field2,

> field3 FROM Table",
> >conn );
> >SqlCeCommandBuilder cb = new SqlCeCommandBuilder(dAdap);
> >dAdap.Fill( dSet, "Table");
> >dataGrid1.DataSource = dSet.Tables["Table"];
> >
> >It works fine except one thing:
> >Let's say I have 3 records in the table and I insert two

> more with the
> >commands:
> >
> >dSet.Tables["Table"].Rows.Add(new Object[]

> {null, "Value1", "Value2"});
> >dAdap.Update(dSet,"Table");
> >
> >If I want to delete the last two records the following

> error message appear:
> >"Concurrency violation: the DeleteCommand affected 0

> records."
> >
> >There is no problem with deleting the first three records.
> >
> >I'm using the following code to delete particular record:
> >dr = dSet.Tables["Table"].Rows[dataGrid1.CurrentRowIndex];
> >dr.Delete();
> >dAdap.Update(dSet,"Table");
> >
> >Thank you
> >Gec
> >
> >
> >.
> >



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off