Group: Forum Members
Posts: 448,
Visits: 12K
|
This is the structure of the BO that Has Data:
CREATE TABLE [dbo].[Contestants](
[rodeoId] [int] NOT NULL,
[membershipCD] [char](1) NOT NULL,
[membershipNumber] [int] NOT NULL,
[contestantName] [varchar](50) NOT NULL,
[invertedName] [varchar](50) NOT NULL,
[city] [varchar](30) NULL,
[state] [varchar](10) NULL,
[creditCD] [char](1) NULL,
[circuitCD] [char](3) NULL,
[contestantId] [int] NOT NULL,
[subjectToWithholdings] [bit] NULL,
[nationality] [varchar](50) NULL,
[contestantGivenName] [varchar](50) NULL,
[contestantNumber] [int] NULL,
This is the Structure of the BO I want to Copy the Data TO and Save:
CREATE TABLE [dbo].[Contestants](
[ContPK] [int] IDENTITY(1,1) NOT NULL, This is My Primary Key
[RodeoID] [int] NOT NULL,
[MembershipCD] [char](1) NOT NULL,
[MembershipNumber] [int] NOT NULL,
[ContestantID] [int] NOT NULL,
[ContestantNumber] [int] NOT NULL,
[ContestantName] [varchar](50) NOT NULL,
[InvertedName] [varchar](50) NOT NULL,
[ContestantGivenName] [varchar](50) NOT NULL,
[City] [varchar](30) NOT NULL,
[State] [varchar](10) NOT NULL,
[CreditCD] [char](1) NOT NULL,
[CircuitCD] [char](3) NOT NULL,
[SubjectToWithHolding] [bit] NOT NULL,
[Nationality] [varchar](50) NOT NULL,
[EventBB] [char](2) NOT NULL,
[EventBR] [char](2) NOT NULL,
[EventGB] [char](2) NOT NULL,
[EventRB] [char](2) NOT NULL,
[EventSB] [char](2) NOT NULL,
[EventSR] [char](2) NOT NULL,
[EventSW] [char](2) NOT NULL,
[EventTD] [char](2) NOT NULL,
[EventTR] [char](2) NOT NULL,
[Fee] [numeric](9, 2) NOT NULL,
Now when I copy the data since the contpk is not in the original table it does not show up in the RodeoBO. Since it is my PK the Save does not work or at least that is the way I understand it. If you need more info please let me know. Thanks for your help.
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 7K
|
Terry, I have been away for a while and as you have noticed haven't been out here. But I think that this is getting way more complicated that it needs to be. First, from what I understand, you have two different BO structures and are trying to pass the data from one into the other. Is this correct? Second, moving data between BOs is actually something that can be done easily and there are a few gotchas if the structure are different and you are trying to save. For example the BO has the AllFieldsList which is used by the BO when saving a record so it knows how to produce the UPDATE, etc. If you have columns that do not exist within the BO but are expected, then you would want to use the ExcludeFieldsFromUpdate/Insert on the BO to prevent the BO from trying to save column values that are not there. Finally, if this doesn't get you going, the I recommend created a quick sample showing what you are trying to do so that there is no guess work as it will help you get an answer more quickly.
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
You might try using the SetDefaultValues event to get the work done. You might have to add a property to the ContestantsRodeoBO so it knows when to use this. I got busy and haven't been following this completely, so I might be way off...
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
You can setup a Bo without a primary key. Look in the help file or the forums for samples. I am not in the office today.
Edhy Rijo
|
Group: Forum Members
Posts: 448,
Visits: 12K
|
The ContestantsRodeoBO does have a PK in the database and it shows up in the Business Object Mapper called contpk. The ContestantsPRCABO does not have this field in it at all since it does not use a PK. I did not design it I just have to use it. So when the data gets copied no contpk field shows up in the ContestantsRodeoBO1 and therefore I can not set up a loop to fill it with -1. ?
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Terry Bottorff (10/04/2009)
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.
Ok, lets clear up some things: ContestantsRodeoBO does have a PK field, but it is not the same as the ContestantsPRCABO1 pk field, right? If so, when you copied the data, in the visualizer what is the value of the ContestantsRodeoBO PK field?, it should be -1, if not, then in the for..next loop, just set the value of the PK field to -1 and try again.
Edhy Rijo
|
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.
|
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
|
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
|
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.....
|