Concurrency violation

R

Raymond

Hi.

I have some problems with Concurrency Violation. I have
searched the Newsgroups here but haven't found the
answers I'm looking for.

I allways get (Concurrency violation: the DeleteCommand
affected 0 records.) when I first add a row and after
update the database delete the row and then save again. I
want to know what I'm doiong wrong.

This is a single user application, I allways get the
error and cannot se what I'm doing wrong.

The database I'm using is Access.

I have a sample code here: VB.NET
http://www.xsoft.se/cv.zip

/Raymond
 
N

Norman Yuan

Without seeing your code, it is hard to say why you get concurrency
violation. Here is my guess:

When you populate a DataSet(DataTable) with data from database, by default,
DataAdapter calls AcceptChanges(), so tah all rows' RowState is "Unchanged",
indicating data in DataSet(Table) are the same as in database.

If you add a new row, then that row's state is "Added". If for some reason
you decide to delete that row from DataTable before you update data to DB or
before you call AcceptCahnges(), that row's state becomes "Detached". Now,
when update table to database, the detached row will not be sent to
database, so it will not cause Concurrency Violation. the detached row
remains in DataTable until AcceptChanges() is called.

To cause Cocurrency Violation as you described, it could be like this: you
add a new row (State="Added"); for some reason you called AcceptChanges()
without updateing DataTable's change back to database, so that th row's
state becomes "Unchanged"; then you delete this row from DataTable
(State="Deleted"); now, whet update back to database, since the deleted row
does not exist in database, hence, "Affected 0 record" and Concurrency
Violation.

HTH
 
D

David Sceppa

Raymond,

It sounds like the insert succeeded, but that there's some
database-generated data (auto-increment, default, etc.) that you
have not yet retrieved into the DataRow. Thus, when you try to
modify the DataRow and submit the change, the update attempt
fails.

There's some sample code in the SDK that describes how to
fetch a new auto-increment value back from an Access database in
"Retrieving Identity or Autonumber Values".

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 
R

Raymond

There it is!
Thank you. Yes it was the autoincrement. Thank you.

Maby you can help me with my second problem.
I still have my master-detail form with a DBGrid. I
create a new record in the master table and add some
records in the DBgrid. The problem now is that the grid
doesn't know the Key in the master table. The user enters
the key so the key is present in the form in a textbox
but how can I tell the grid what the Key is??

Samplecode: www.xsoft.se/cv.zip

/Raymond
 
W

William \(Bill\) Vaughn

Did you read my article on handling identity issues? See
www.betav.com/articles.htm


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

There it is!
Thank you. Yes it was the autoincrement. Thank you.

Maby you can help me with my second problem.
I still have my master-detail form with a DBGrid. I
create a new record in the master table and add some
records in the DBgrid. The problem now is that the grid
doesn't know the Key in the master table. The user enters
the key so the key is present in the form in a textbox
but how can I tell the grid what the Key is??

Samplecode: www.xsoft.se/cv.zip

/Raymond
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top