Concurrency violation: the UpdateCommand affected 0 of the expecte

G

Guest

Hi
When I want to update a record folowing exception has been appeared:
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records
Can anyone help me about the cause of the exception?

regards
Mehdi
 
J

Jon Skeet [C# MVP]

mkomasi said:
When I want to update a record folowing exception has been appeared:
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records
Can anyone help me about the cause of the exception?

An update command usually contains a "where" clause to update the right
row. In this case, it sounds like the "where" clause didn't match
anything, so it didn't update any rows.

Now, as to why that happened, we'll need more information about what
you're doing...
 
S

sloan

The "canned" MS examples base an update query on values from db, that your
originally read.

empid , lastname , firstname
101, john , smith

When you read the data ......you get that data (101, john, smith)

While you are looking at it, somebody changes the lastname to 'jones'

so in the real db, you have
101, john , jones

You change hte lastname to Peabody. So you want to write "John" "Peabody"
(101) to the database.

When you run your update, the code is probably running something like this

Update Emp Set LastName='Peabody', FirstName='John'
WHERE
LastName='Smith' and FirstName='John' and EmpID=101

Because somebody else updated the db (to jones)....your query runs, but
returns 0 rows, because there a match (anymore).

Thus the kinda crappy "Concurrency" exception. You getting some pre-canned
MS string.
Its basically saying "I was supposed to find 1 row, but I didn't find that
row, THEREFORE, somebody else must have changed the row.
 

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