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


Author
Message
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 Code That causes the Problem is:





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



Next



End If





The Lines above the ................... work fine but the ones below Do Not. ????



In the New Table(where the data is going) I have contraints like the following:



ALTER TABLE [dbo].[Contestants] ADD CONSTRAINT [DF_Contestants_EventBB] DEFAULT ('') FOR [EventBB]



ALTER TABLE [dbo].[Contestants] ADD CONSTRAINT [DF_Contestants_SubjectToWithHolding] DEFAULT ((0)) FOR [SubjectToWithHolding]



CONSTRAINT [PK_Contestants] PRIMARY KEY CLUSTERED

([ContPK] ASC

)



The Error I get is a lengthy one:





MicroFour.StrataFrame.Data.DataLayerSavingException was unhandled by user code

Message="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'."

Source="MicroFour StrataFrame Business"

StackTrace:

at MicroFour.StrataFrame.Data.DataLayer.UpdateDataTable(DataTable TableToUpdate, Boolean Transactional, String TransactionKey)

at MicroFour.StrataFrame.Data.DataLayer.Save(DataTable TableToSave, Boolean Transactional, String TransactionKey)

at MicroFour.StrataFrame.Business.BusinessLayer.Save(Boolean Transactional, String TransactionKey)

at MicroFour.StrataFrame.Business.BusinessLayer.Save()

at DevExpressGridTwoDataBasesSF.Form1.Button3_Click(Object sender, EventArgs e) in C:\VSProjects\DevExpressGridTwoDataBasesSF\DevExpressGridTwoDataBasesSF\Form1.vb:line 53

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)

at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

InnerException: System.Data.SqlClient.SqlException

Class=16

ErrorCode=-2146232060

LineNumber=1

Message="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'."

Number=207

Procedure=""

Server=".\sqlexpress"

Source=".Net SqlClient Data Provider"

State=1

StackTrace:

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

at System.Data.SqlClient.SqlDataReader.get_MetaData()

at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)

at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)

at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)

at MicroFour.StrataFrame.Data.DbDataSourceItem.InternalExecuteReader(DbCommand Command, Boolean IsTransactional, String TransactionKey)

at MicroFour.StrataFrame.Data.SqlDataSourceItem.UpdateRow(QueryInformation QueryInfo, DataRow RowToUpdate, ConcurrencyExceptionHandler ConcurrencyHandler, AddRowErrorHandler RowErrorHandler, Boolean RecreateCommand)

at MicroFour.StrataFrame.Data.DbDataSourceItem.UpdateRow(QueryInformation QueryInfo, DataRow RowToUpdate, ConcurrencyExceptionHandler ConcurrencyHandler, AddRowErrorHandler RowErrorHandler)

at MicroFour.StrataFrame.Data.DataLayer.UpdateDataTableThread(Object ThreadParams)

InnerException:





Any help would be greatly Appreciated. TIA.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
It is a bit hard to say what is going on, but an Invalid Column name error usually indicates that the underlying SQL table doesn't have that column within it. The ContestantsProRodeoBO was mapped against the right table? I.e. that that table has the SubjectToWithHolding, and EventBB, etc. columns? I would seem that you did a partial build of the BO, since it appears that you have the strong typed properties. But since it is also complaining about the PK for the table, it sure seems like the BO and the underlying database aren't in synch. I'd double check that first (check tablename, columns etc with db table/columns).
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 BO mapper Shows all the fields and the fields are found in the Database Table so is there somewhere else I should check? Does the PK have to be defaulted to -1?
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 BO's don't have to have the same structure do they? TIA.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I'd also double check the designer file of the BO. Check the TableName property, check the field name properties (the ones that list the field names in the BO). (Or just do a partial rebuild...then you'll know that the BO matches.)



The BO doesn't have to have the same structure as the table, but you then need to set the exclude on insert and exclude on update properties (can't recall exact names) because the BO will use all the mapped fields when it creates the SQL to do an update or insert and if the structure doesn't match, you need to exclude those fields that aren't actually used. However, because you're having trouble with the PK, I'm thinking something else is going on.



Likely, you're best bet is to attempt to make a sample app that reproduces the issue. Start with a simple maintenance form using the BO and confirm that the BO will load, save, insert, delete data into the table. If that works, then move on to a grid (maybe try a plain vanilla .NET grid first). If that works, move on to the copying of data from one BO to another. I can't tell you how many times I've had a thorny issue that got resolved by following a process like this.
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 will try a simple maintenance form. That is a good idea. I recreated the entire project and I am still getting the same error but I will try the maintenance form now and see what that brings. I'll be back.
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
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
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
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
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
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 (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/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

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