Resolved Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

Socarsky

Well-known member
Joined
Dec 27, 2012
Messages
173
Location
Jakarta/Indonesia
Programming Experience
Beginner
My problem is when I try to modify a cell of row after its just updated to the database then a thrown occurs. Because it happens only new row add with data after the program execute not that the other come up with first running of the program. I can modify any cell and update when I execute the program but when after a new row data recorded(update) to the database then modify its data and update that error occurs.
VB.NET:
Private SqlAdapter As New SqlDataAdapter("Select * from tblContacts", SqlConn)
SqlAdapter.Update(TheDataTable)

Below is my project screen capture if you want to see:
http://img819.imageshack.us/img819/2586/concurrencyerror.jpg
 
Last edited:
A concurrency violation occurs when the data in the database for a row that you're trying to update doesn't match the original data fro the row in your app. So, have you actually compared the original data in your DataRow to the data in the database? That seems like the logical first step to me.
 
A concurrency violation occurs when the data in the database for a row that you're trying to update doesn't match the original data fro the row in your app. So, have you actually compared the original data in your DataRow to the data in the database? That seems like the logical first step to me.

I know that please give me suggestions as code. Thanks
 
I've told you what to do. Do it. If you can post back and tell us what the difference between the two sets of data is then we might be able to help but you've already been provided plenty of suggestions on this topic so it's a waste of time to keep guessing.
 
Finally

I just found by myself and that made me happy. Now things alright, I can updated records as I want without Concurrency issue. This case dismiss :D
I just added below under this line of code:
VB.NET:
x = SqlDA.Update(TheDataTable)
TheDataTable.Clear()
        SqlDA.Fill(TheDataTable)
 
I just found by myself and that made me happy. Now things alright, I can updated records as I want without Concurrency issue. This case dismiss :D
I just added below under this line of code:
VB.NET:
x = SqlDA.Update(TheDataTable)
TheDataTable.Clear()
        SqlDA.Fill(TheDataTable)
That's a terrible solution. If you write your code properly then there should be no need to throw away all the data you already have and get the whole lot again.
 
You prefer to use words jmcilhinney, better to show us your perfect code and show your talent :lookaroundb: then we can get better idea.
 
I've shown you the code. I've also told you to compare the data in the application to that in the database to determine exactly where the difference lies but you are apparently unwilling to do that.
 
I've shown you the code. I've also told you to compare the data in the application to that in the database to determine exactly where the difference lies but you are apparently unwilling to do that.
Reminds me one more pls. yeah I can see those two line of code not wise... but thats my solution and its really work, yeah maybe quality is low but I am a rookie
 
I've replied to your posts in at least one thread (although I think it's two) saying that you need to ensure that values generated by the database on insert are retrieved into the application. I even wrote code to show how to do that in one of the threads. I don't recall your replying on either occasion (certainly not on the one where I provided code) to indicate whether you'd tried what I said and whether it solved the issue.
 
Back
Top