Grig,
As to why it happens sometimes and not others, I don't know and haven't ever really taken the time to pinpoint which circumstances cause it ... and, to be honest, suggesting you do a BindingContext[].EndCurrentEdit() is probably not a good suggestion either ... I have found that sometimes it does not work (does not cause the ds.HasChanges() to become true). The DataRow.EndEdit() method seems to work much better. Here's a method that I have coded into my base Form class to check for this particular problem. I always call it before I do a save:
protected virtual void ForceChangedRows(DataSet ds)
{
if (ds == null)
return;
for (int nTable = 0; nTable < ds.Tables.Count; nTable++)
{
for (int nRow = 0; nRow < ds.Tables[nTable].Rows.Count; nRow++)
{
if (ds.Tables[nTable].Rows[nRow].HasVersion(DataRowVersion.Proposed))
{
ds.Tables[nTable].Rows[nRow].EndEdit();
}
}
}
}
~~Bonnie
>Hi, Bonnie
>
>Ok, thank you, I've got the idea. However, now is something else that bothers me. Why "sometimes"? Kevin's book doesn't have that in the code, however the code does save data. What's the difference and whey I am supposed to commit data from BindingContext and when I am not?
>
>>Grig,
>>
>>Sometimes you need to do an .EndEdit() or an .EndCurrentEdit(). If you put this code:
>>
>>this.BindingContext[dsBook].EndCurrentEdit();
>>
>>before you save, you should see that dsBook.HasChanges() should now be true.
>>
>>~~Bonnie