HighTechTalks DotNet Forums  

Re: Concurrency violation on Update DeleteCommand

Dotnet Framework (Compact Framework) microsoft.public.dotnet.framework.compactframework


Discuss Re: Concurrency violation on Update DeleteCommand in the Dotnet Framework (Compact Framework) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Gec
 
Posts: n/a

Default Re: Concurrency violation on Update DeleteCommand - 07-08-2003 , 04:00 AM






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 (AT) nada (DOT) nada> wrote

Quote:
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 Search this Thread
Search this Thread:

Advanced Search
Display Modes

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.