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
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

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
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. ?

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
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

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
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...
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.

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
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.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Boy, there a lot of NOT NULLs in the target table Blink



I think the SetDefaultValues is going to be your friend (either handle this within ContestantsRodeoBO itself, or add handlers in the form/code that is doing this work on the SetDefaultValues event of ContestantsRodeoBO1). You need to set default values for all the columns in the target table that won't be filled in. Usually when you use the BO to add a new row, it will deal with the PK automatically. Otherwise you'll have to deal with that as well.
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Terry,



What I meant for you to post was an actual sample. We can bounce back and forth another 30 posts. This thread has gotten really long since you started it and you still do not have an answer.



If you can post a sample so that we do not have to try and get all of your structures and development environment in our heads without being able to actually see it, you will get some answers much more quickly.



This is a policy that we use even internally when we run into things. It helps lower the frustration level on all parties and the ultimate goal is helping you find an answer...but all of our standard suggestion have not seemed to help.



If you need to post an mdf of SQL backup and a small sample, not your actual full application, but a sample app with BOs that reproduces the issue, that should be your next step. Thanks.
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
The two databases are secretarysystem and rodeo with secretarysystem.dbo.contestants having the data I want into rodeo.dbo.contestants.



The Visualstudio 2008 project is: DevExpressGridTwoDatabasesSF.



Attachments
rodeo.zip (118 views, 1.00 MB)
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
Sorry Terry, I don't have devExpress so I will not be able to test your sample project.

Edhy Rijo

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