StrataFrame Forum

How to use CopyDataFrom to add a new record?

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

By Aaron Young - 10/18/2009

Hi,



I am trying to use the CopyDataFrom method to copy the contents of one BO into an empty second BO and to then assign new primary keys to the second BO so that I can add them as new records. However, when I do this and save, it overwrites the original records with the new primary keys and no new records are added.



I think I am missing something to get the records in the second BO added instead of updated.



Is this the best way to take a record and duplicate it? If so, have I missed something?



Thanks in advance,



Aaron
By Edhy Rijo - 10/19/2009

Hi Aaron,



When you use the BO.CopyDataFrom() it will ignore the Row State so you will need to loop the copied records and set the Row State, the code below should do the trick:



For Each StockBO As bizTransactionItemsStock In Me.BizTransactionItemsStock1.GetEnumerable()

StockBO.CurrentRow.SetAdded()

Next



By Aaron Young - 10/19/2009

Hi Edhy,



Thanks for that - it worked Smile



Think I was getting hung up on trying to make the BO change editing state to adding. This method doesn't need that at all.



Thanks again.



Aaron
By Edhy Rijo - 10/19/2009

You are welcome Aaron.



There is also an enhancement request to add a property or flag to the BO.CopyDataFrom to update the row state in a single pass. Hope to see that enhancement soon Wink