Thursday, April 19, 2007
RSS Reader: Day 6
No progress yesterday on the RSS Reader. I'm still digging into Typed DataSets. But, even that didn't go very far for reasons too boring to discuss here. I did find out why the calls to authors.AcceptChanges() didn't work. First, I looked in the help file. It says, "Resets the object’s state to unchanged by accepting the modifications." Umm. ok. So, the state of the object is set to unchanged but the modifications were accepted.
Next, I went to the book Programming with ADO.Net 2.0 Core Reference. It explained things much better:
"If you call the AcceptChanges method on your DataSet, ADO.Net will accept all pending changes stored in the DataRow objects in your DataSet. Any row whose RowState property is set to Added or Modified will have their RowState property set to Unchanged. Doing this will also reset the "original" values for the DataRow to the current contents of the DataRow. Any DataRow objects marked as Deleted will be removed from your DataSet when you call AcceptChanges.
When the SqlDataAdapter object successfully submits pending changes stored in a DataRow object, it implicitly calls the AcceptChanges method on that DataRow."
So, what happens is that when you call AcceptChanges, it updates the values in the row and resets the flag that indicates there were changes. But it doesn't update the database! To do that, you need to call AcceptChanges of the SqlDataAdapter. But it looks at the flag and sees there are no changes, so doesn't do anything. Once again, here is a case of all the books and examples showing calls to AcceptChanges when that isn't what you should be doing.
The solution is exactly what I ended up doing. Don't call AcceptChanges. Just call the TableAdapter's Update method.
Next, I went to the book Programming with ADO.Net 2.0 Core Reference. It explained things much better:
"If you call the AcceptChanges method on your DataSet, ADO.Net will accept all pending changes stored in the DataRow objects in your DataSet. Any row whose RowState property is set to Added or Modified will have their RowState property set to Unchanged. Doing this will also reset the "original" values for the DataRow to the current contents of the DataRow. Any DataRow objects marked as Deleted will be removed from your DataSet when you call AcceptChanges.
When the SqlDataAdapter object successfully submits pending changes stored in a DataRow object, it implicitly calls the AcceptChanges method on that DataRow."
So, what happens is that when you call AcceptChanges, it updates the values in the row and resets the flag that indicates there were changes. But it doesn't update the database! To do that, you need to call AcceptChanges of the SqlDataAdapter. But it looks at the flag and sees there are no changes, so doesn't do anything. Once again, here is a case of all the books and examples showing calls to AcceptChanges when that isn't what you should be doing.
The solution is exactly what I ended up doing. Don't call AcceptChanges. Just call the TableAdapter's Update method.
Subscribe to Posts [Atom]