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


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Nope, it does not.



Did you try it?

Edhy Rijo

Terry Bottorff
Terry Bottorff
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K 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 (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K 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

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K 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

Terry Bottorff
Terry Bottorff
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K 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 (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K 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

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Terry Bottorff (10/02/2009)
I will try your 2nd option and let you know about it. Will only the fields that are identically named get copied? TIA. Thanks for your input.




Yes, that should be the result. Also try setting the BO.FieldsToExcludeFromInsert and BO.FieldsToExcludeFromUpdate with the field names that are giving you the error.

Edhy Rijo

Terry Bottorff
Terry Bottorff
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 448, Visits: 12K
Edhy I tried your Option 1 and I looked at the BO where the data is being copied with the Visualizer and all of the data is there but when I execute the me.ContestantsProRodeoBO1.Save() and I get exactly the same message about certain fields being invalid.?????

I will try your 2nd option and let you know about it. Will only the fields that are identically named get copied? TIA. Thanks for your input.
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Terry,



Move this code me.ContestantsPRCABO1.MoveNext() after the For..Next loop.



Also may I suggest any of these approaches for you to try:



'-- Option 1:

' Use the BO.GetEnumerable() to loop the BOs.

For Each PRCABO1 As ContestantsPRCABO1 In Me.ContestantsPRCABO1.GetEnumerable()

With Me.ContestantsProRodeoBO1

.NewRow()



.RodeoID = PRCABO1.rodeoId

.MembershipCD = PRCABO1.membershipCD

.MembershipNumber = PRCABO1.membershipNumber

.Nationality = PRCABO1.nationality



'-- This assign may not be needed since you are

' creating a new record and those should be

' the default value.

.Fee = 0

.EventBB = ""

.EventBR = ""

.EventGB = ""

.EventRB = ""

.EventSB = ""

.EventSR = ""

.EventSW = ""

.EventTD = ""

.EventTR = ""

End With

Next

If Me.ContestantsProRodeoBO1.IsDirty() Then

Me.ContestantsProRodeoBO1.Save()

End If



'-- Option 2:

' Use the BO.Filter if needed and then the BO.CopyDataFrom to copy the data

' to the ContestantsProRodeoBO1

Me.ContestantsPRCABO1.Filter = "Whatever condition you want, if needed to be filter"

Me.ContestantsProRodeoBO1.CopyDataFrom(Me.ContestantsPRCABO1, BusinessCloneDataType.ClearAndFillFromDefaultView)

' That will copy the data to the new BO, then you manipulate the fields if needed, by using ContestantsPRCABO1.GetEnumerable()

' Look at those cocepts in the help file or in the forum for many samples on how to use it.

If Me.ContestantsProRodeoBO1.IsDirty() Then

Me.ContestantsProRodeoBO1.Save()

End If


Edhy Rijo

Terry Bottorff
Terry Bottorff
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 448, Visits: 12K
First Off a maintenance form on the the BO that has the Data works fine and a maintenance form on the empty BO that will receive the data also works fine. So????? I guess the sync between the database and the BO's seem to be OK. Since both tables have exactly the same name but not the same structure I had to make sure the FillDataTable("Select * from secretarysystem.dbo.contestants") and the other was FillDataTable("Select * from rodeo.dbo.contestants") but then the maintenance forms worked great.





If Me.ContestantsPRCABO1.MoveFirst Then

Dim howmany As Integer

howmany = Me.ContestantsPRCABO1.Count

MessageBox.Show(howmany.ToString, "Number of contestants")

Dim cnt As Integer

For cnt = 1 To howmany

Me.ContestantsProRodeoBO1.NewRow()



Me.ContestantsProRodeoBO1.RodeoID = Me.ContestantsPRCABO1.rodeoId

Me.ContestantsProRodeoBO1.MembershipCD = Me.ContestantsPRCABO1.membershipCD

Me.ContestantsProRodeoBO1.MembershipNumber = Me.ContestantsPRCABO1.membershipNumber

Me.ContestantsProRodeoBO1.Nationality = Me.ContestantsPRCABO1.nationality

...............

Me.ContestantsProRodeoBO1.Fee = 0

Me.ContestantsProRodeoBO1.EventBB = String.Empty

Me.ContestantsProRodeoBO1.EventBR = ""

Me.ContestantsProRodeoBO1.EventGB = ""

Me.ContestantsProRodeoBO1.EventRB = ""

Me.ContestantsProRodeoBO1.EventSB = ""

Me.ContestantsProRodeoBO1.EventSR = ""

Me.ContestantsProRodeoBO1.EventSW = ""

Me.ContestantsProRodeoBO1.EventTD = ""

Me.ContestantsProRodeoBO1.EventTR = ""

Me.ContestantsProRodeoBO1.Save()



me.ContestantsPRCABO1.MoveNext()

Next



End If





Now I moved the Me.ContestantsProRodeoBO1.Save() after the Next and before the End IF and put a Break Point on it. I looked at the Me.ContestantsProRodeoBO1.CurrentView in the visualizer and all the records are there with the ContPK filled in with -1...-1293 and the other fields filled in also.

BUT when I execute the Me.ContestantsProRodeoBO1.Save() I get this error(s):



Invalid column name 'SubjectToWithHolding'. Invalid column name 'EventBB'. Invalid column name 'EventBR'. Invalid column name 'EventGB'. Invalid column name 'EventRB'. Invalid column name 'EventSB'. Invalid column name 'EventSR'. Invalid column name 'EventSW'. Invalid column name 'EventTD'. Invalid column name 'EventTR'. Invalid column name 'Fee'. Invalid column name 'ContPK'. Invalid column name 'ContPK'.



Any Ideas?????? TIA
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