|
tech
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.I have the following method in an object name SpouseBLL: [System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Update,true)] public bool UpdateSpouse(Spouse obj) { //Create a new product row instance MRF.MRF_SpouseDataTable spouses = Adapter.GetSpouseByGuestId(obj.GuestId); MRF.MRF_SpouseRow spouse = spouses[0]; spouse.FirstName = obj.FirstName; spouse.LastName = obj.LastName; spouse.GuestId = obj.GuestId; spouse.MobilePhone = obj.MobilePhone; spouse.Email = obj.Email; spouse.LectureLanguage = obj.LectureLanguage; spouse.DateOfBirth = obj.Dob; //Add the new spouse int rowsAffected = Adapter.Update(spouse); return rowsAffected == 1; } When I try to update the database I receive the following error: >>>>>>>>>>>Concurrency violation: the UpdateCommand affected 0 of the I have written the exact method for another object and it works with no >>>>>>>>>>>expected 1 records. problem. Thanks, David Hello David,
First of all, I would like to confirm my understanding of your issue. From your description, I understand that you are getting a DBConcurrencyException when trying to use a DataAdapter to update the data source. If there is any misunderstanding, please feel free to let me know. This is a typical concurrency issue. The DBConcurrencyException is thrown by a DataAdapter during the update operation if the number of rows affected equals zero. (http://msdn.microsoft.com/en-us/library/system.data.dbconcurrencyexception. aspx) For this kind of issue, there are two possibilities. 1. Another user is trying to update data in database. For the data is modified, our DataAdapter cannot find the original data and throws the exception. So, we have to write our logical codes to handle this situation following the try/catch structure found in, http://msdn.microsoft.com/en-us/library/y8fyz6xy(VS.80).aspx 2. There is a problem related to UpdateCommand. If this is case, I would like suggest you use the tool SQL profiler in the server side to observe every incoming request. Then we can know what update command cause this exception. See the http://msdn.microsoft.com/en-us/library/ms187929.aspx. Have a good weekend! Best regards, Ji Zhou (v-j***@online.microsoft.com, remove 'online.') Microsoft Online Community Support Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msd***@microsoft.com. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Hello David,
I am writing to check the status of the issue on your side. Are my suggestions helpful for your scenario? If you need any future assistance, please feel free to let me know. I will be more than happy to be of help. Have a great day! Best regards, Ji Zhou (v-j***@online.microsoft.com, remove 'online.') Microsoft Online Community Support |
|||||||||||||||||||||||