StrataFrame Forum

How to append without seeing save changes

http://forum.strataframe.net/Topic17212.aspx

By Greg McGuffey - 6/20/2008

I attempting to update the current row after a save (to get the values of some calculated columns from SQL Server). I have a method that uses AppendDataTable to update a single row. When this is called, the BO is dirtied and then I get a "do you want to save changes" message. From the user's perspective, what they see is:



- they save the record by clicking on "Save"

- Then they are asked if they want to save changes (duh, like, of course I do...I just clicked "Save"!)



Now, if they click Yes or No, it makes no difference, as the changes are fresh from the DB in any case. Cancel makes no sense as I'm doing this in AfterSave and the form has already put the BO into idle state.



So, what am I doing wrong here/how can I deal with this?
By Edhy Rijo - 6/20/2008

Hi Greg,

I understand that in the AfterSave() event you have code to update the current row? If this is the case, then the BO.IsDirty will be True causing the ask to save message, right?

By Greg McGuffey - 6/20/2008

Yep. That is correct. The specific line that causes the BO to become dirty again (after all, it was just saved), is the AppendDataTable call.
By Edhy Rijo - 6/20/2008

How about calling the BO.CurrentDataTable.AcceptChanges() in the AfterSave(). 

That may not be the best fix, but it may buy you some time. Wink

By Greg McGuffey - 6/20/2008

Yeah, I tried that. I tried to call it right after calling AppendDataTable(). Unfortunately, the message already occurred. I.e. the bo is dirtied by the AppendDataTable call (apparently), and user is prompted to save changes before it returns.
By Trent L. Taylor - 6/23/2008

Greg,

You might want to try an ImportRow or LoadDataRow since you have a record from a DataTable that you are trying to import.  You can specify whether or not to preserve the row state (which is sounds like in this case you wouldn't want to.  It may look something like this:

LoadDataRow:

'-- Create the values collection that will match the structure of the data table
Dim myValues As Object() = New Object() {"Col1", 1234, DateTime.Now}

'-- Insert (or update) the row with the values that you want. 
MyBO.CurrentDataTable.LoadDataRow(myValues, LoadOption.OverwriteChanges)

ImportRow:

Me.CurrentDataTable.ImportRow(MyTable.Rows(0))