Last night, Debug fell three in the morning, is a 1 error. That is, the result is one or less than the result of the expected.
For this bug, it struggled for 4 hours because it didn't happen every time. After repeated trials, this 1 error will only appear when it is deleted when the Dataset will only be deleted. So start single-step tracking, check the data in memory, and the god of the god will not find any errors, the data is completely and imagined. Why is the data that is written during the database? Is SqlDataAdapter with bug?
I still assume that this bug is my own until I confirm. After careful observation, there is a problem when the last step is written to the database, it is clearly 32 to write into the database to become 31 ...
Silent me ...
Careful thinking about me this field is autoIncrement, isn't this question?
After repeated exploration, I finally discovered the problem, haha! Many problems really say that it is like this, but before wearing it ... hey!
Read the data from the database table to fill in the DataSet, and "Column" is named. At this point, "Columns" in the memory is exactly the same, including the AutoICrement property of the ID field. At this time, the maximum value of the ID field is 30, and the self-adding seed is 31.
Now operate "Column" in memory. Insert two lines and delete the line in front. At this point, the maximum value of the ID field of "Column" in memory should be 32, and the sub-seed is 33 (the line of ID 31 is deleted). But "Column" in these operating physical databases is not known.
Call the Update method for SqlDataAdapter now. When the child adds field is ignored in the database, its value is determined completely according to its own seed. Therefore, when writing to the database, the sub-plant seed seed of the Id field in the "Column" in the physical database is 31, so 32 is inexplicably turned 31.
It is also convenient to find the problem. It is also convenient to solve it. It's just the first time I encountered this problem, I feel that anything will be depressed. This issue is a bit value, so record it. Give a wake up to the peers that have not met this problem :)
Debug
Just as the chasing beauty, the process is painful, the ending is happy.