Oct 26, 2010
When my project starts, it first checks for the existence of certain rows in the database. During testing, I often delete these rows, as they get kind of messed up over time due to all the odd tests I am running. For that reason, if when the project starts, if the records are not there, the program first creates them.The records are pretty static over the lifetime of the project, so they are held in a dataset for ready access from various parts of the program. Therefore, if the records are not in the database, the records are added to the dataset, and the dataset is updated back to the database. This works without any issues.However, one of the easiest actions to take will cause one of these records to change two fields, and a new record will be added. Those are all the changes that are caused by this action. Those changes are then updated to the database...or so I hoped, but when I try that I get an exception stating:[code]I have looked at the datatable that is being updated, and there are, as I expect, two records being changed. One of the records is the new one that is being added, while the second record is the record that was changed. I have noted that the change is, in fact, different from what is in the database, so this really IS an update.
View 2 Replies
However, I also noted that if I then stop the program and start it again, all is well. This indicated to me that it was actually the routine that created the records that was causing the trouble. Therefore, to test this out, I tried a totally horrible solution. I altered the method that writes to the new records to the database so that after it wrote each record, it would clear the whole dataset and fill it all again. That's obviously a terrible thing to do, but it works. If I write each record, throw out the dataset and re-create it, then I don't get any exceptions when I later try to modify it.This makes no sense to me. What am I doing in that first method that could be putting the Dataset into a state where it fails on any further modifications? I should add that the code that actually pushes the changes to the dataset down to the DB is the same for both methods. In fact, the database is updated in an UpdateDB method that is called from that first method (which creates the initial records if they are missing), as well as being called by the other methods that alter the dataset. I have also confirmed that ANY alterations I want, whether they add, remove, or just alter records, works fine. It is only that one method that creates the initial records that is causing me trouble. Moreover, it is not the actual update of the DB that is doing it, since that same method works fine ever after. Further testing has showed that the issue is row by row. As each initial row is added, it can't be modified by any other code until the dataset has been re-read from the DB. url...