Trying to Take Data from One BO to Another (Not the Same Structure)


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Also remember to check the help file for more detail on using the methods.



Here is quote from the CopyDataFrom description in the help file:





As described above, there are two distinct ways to copy data into a business object. Data can be copied from another business object or from a DataTable. When data is copied using the Clear copy types, the file structure does not have to match the business object structure. However, when an Append copy type is used, the structure of the copy source must match the structure of the business object, or an error will occur.





So based on that quote, my 2nd option should work without the need to exclude any field.

Edhy Rijo

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
I tried the following code and the if me.ContestantsRodeoBO1.IsDirty is not true so then I put the statement Me.ContestantsRodeoBO1.Save() and it executes without error But it Does not Save anything.

I used the visualizer on me.ContestantsRodeoBO1.CurrentView and all of the data is there except the column ContPK which is the primary key of the BO that I am putting the data into. This column does not exist in the original BO and I guess that is why it does not show up in the copeid data. Therefore, I suppose that is why no data is saved.





If Me.ContestantsPRCABO1.MoveFirst Then

ContestantsRodeoBO1.CopyDataFrom(ContestantsPRCABO1, MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)

End If



If Me.ContestantsRodeoBO1.IsDirty Then

Me.ContestantsRodeoBO1.Save()

End If



Me.ContestantsRodeoBO1.Save()





I'm at a lost as to what to do??? TIA.
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Terry Bottorff (10/04/2009)
I'm at a lost as to what to do??? TIA.




Don't worry, this is part of the learning curve. BigGrin



I believe the problem is that the CopyDataFrom does not keep the RowState so you will have to loop one more time in the copied BO and change the RowState for all the records, so the Save() can actually save them. Something like this could do the trick:



If Me.ContestantsPRCABO1.Count > 0 Then

'-- Copy data to Me.ContestantsRodeoBO1

Me.ContestantsRodeoBO1.CopyDataFrom(Me.ContestantsPRCABO1, MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)



'-- Loop the Me.ContestantsRodeoBO1 and change the RowState if needed

For Each contestantsBO As ContestantsRodeoBO In Me.ContestantsRodeoBO1.GetEnumerable()

'-- Change the CurrentRow state to make sure the record will be saved in the Activation process.

If contestantsBO.CurrentRow.RowState = Data.DataRowState.Unchanged Then

contestantsBO.CurrentRow.SetModified()

End If

Next



'-- Save the Record

If Me.ContestantsRodeoBO1.IsDirty Then

Me.ContestantsRodeoBO1.Save()

End If

End If



Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Also you may need to play with the value needed for each RowState, in my sample before I am using Data.DataRowState.Unchange but you may need to use Data.DataRowState.Added so your ContPK gets updated with a new autoincrement value.




Edhy Rijo

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
Does it make a difference that one BO is coming from one database and the other BO is in another database?
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Nope, it does not.



Did you try it?

Edhy Rijo

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
Well Edhy with your new code(Data.DataRowState.Unchange ) I now get this error which I think is a great improvement.



Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.





Of course since the ContPK was not copied I know I need to somehow add it too the BO. In your previous reply you mentioned "you may need to use Data.DataRowState.Added" but I can not seem to find any examples of just how that would work. Is there a sample somewhere???? TIA.



I may just be using the wrong search words to find an example. TIA.....
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Try this:



Just change: contestantsBO.CurrentRow.SetModified()



With contestantsBO.CurrentRow.SetAdded()



That should trigger an "Insert command instead of Update"


Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Terry Bottorff (10/04/2009)
Well Edhy with your new code(Data.DataRowState.Unchange )

Cannot create UPDATE command because the updating DataTable does not contain columns for all PrimaryKeyFields.



Of course since the ContPK was not copied I know I need to somehow add it too the BO..




Yes your contestantsBO must have the ContPK field so it will be properly updated.


Edhy Rijo

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K


For Each contestantsBO As ContestantsRodeoBO In Me.ContestantsRodeoBO1.GetEnumerable()

'-- Change the CurrentRow state to make sure the record will be saved in the Activation process.

If contestantsBO.CurrentRow.RowState = Data.DataRowState.Unchanged Then

'contestantsBO.CurrentRow.SetModified()

contestantsBO.CurrentRow.SetAdded()

End If



Next



If Me.ContestantsRodeoBO1.IsDirty Then

Me.ContestantsRodeoBO1.Save()

End If





I tried the above code and I get the following error:



Cannot create INSERT command because the updating DataTable does not contain columns for all PrimaryKeyFields.



GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search