Click here to Skip to main content
15,899,124 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionTableAdapter.Update problem Pin
ford8627-May-08 10:46
ford8627-May-08 10:46 
Sorry for the long text...

I'm using a dataset for the link between my application and the MS Access database. The problem I have is with the Update function of the table adapter object. The code is really simple and it works very well except in one situation. Here's the code (generated by dragging from the data source to the windows form):

this.tblRequestBindingSource.EndEdit();
this.tblRequestTableAdapter.Update(this.forms_Work_LogDataSet.tblRequest);

The situation when it doesn't work is very specific and I've tried it on several test applications and it seems to be caused by the dataset. When I create a new record and save right away, everything is fine. Then, if I make a modification to the record and save again, an Concurrency Violation exception is thrown. It only happens on new records. I can save as many times as I wish on already existing records, but not on new records.

Usually, Concurrency violation exception is due to the fact that more than one user is modifying the record, but in that case, only one user is modifying the information. It seems as if the first update didn't "EndEdit" even though it was clearly done if you look at my code. That's not good because when I call the update method of the table adapter, it's trying to update every changes made in that table of the dataset, meaning I can never save changes in the application data unless I restart the application because it's always throwing the exception.

I read many things on bypassing concurrency violation exceptions, and for the dataset, it seemed pretty logical to just remove the "optimistic concurrency" option. It didn't work, because well, that's probably not even the reason why it's throwing that exception.

I was wondering if this problem can be solved, without switching to a disconnected mode. I want a solution or a reason as to why we cannot insert a new record and save more than once without leaving the application. This problem can easily be reproduced by dragging a data source on a form and trying exactly what I wrote that isn't working fine. If someone has a solution for that, I'd really appreciate the help.

BTW, I won't accept "Don't use datasets" as an answer unless there really isn't an other solutions...
AnswerRe: TableAdapter.Update problem Pin
Mike Dimmick28-May-08 5:32
Mike Dimmick28-May-08 5:32 
GeneralRe: TableAdapter.Update problem Pin
ford8628-May-08 5:39
ford8628-May-08 5:39 
AnswerRe: TableAdapter.Update problem [modified] Pin
William Ten Broek3-Jun-08 16:12
William Ten Broek3-Jun-08 16:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.