By Terry Bottorff - 4/6/2010
If EventEntriesRodeoBO1.MoveFirst Then
For Each loRodeo As EventEntriesRodeoBO In Me.EventEntriesRodeoBO1.GetEnumerable
Select Case EventEntriesRodeoBO1.eventCD
Case "BB"
ContestantsRodeoBO1.EventBB = EventEntriesRodeoBO1.eventCD
Case "BR"
ContestantsRodeoBO1.EventBR = EventEntriesRodeoBO1.eventCD
End Select
Next
End If
ContestantsRodeoBO1.Save()ContestantsRodeoBO1.Save()
I am trying to iterate thru the parent(evententriesrodeobo1) and update a column in the child(contestantrodeobo1). This code is called from the click of a button on a form. Please note the attached screenshots. The parent child relationship works on the form so what am I missing in the code? I have traced the code and it seems to be doing what I need it to do except the data does not end up in the child in the database?????
I must be brain dead since this seems to be trivial BUT.?????? TIA
|
By Bill Cunnien - 4/6/2010
Have you tried moving the Save() method inside the Select/Case statement? I might try something like this:
Select Case EventEntriesRodeoBO1.eventCD
Case "BB"
ContestantsRodeoBO1.Edit()
ContestantsRodeoBO1.EventBB = EventEntriesRodeoBO1.eventCD
ContestantsRodeoBO1.Save()
Case "BR"
etc.
Couple of questions:
Is there a reason that you are checking to see if the Parent BO has moved to the first BO?
Is there only one child BO per parent? If all of the children (assuming one to many) need to be updated, then you may need to iterate them also.
Not sure if this would work...and, I am losing my VB skills. Sorry.
|
By Edhy Rijo - 4/6/2010
Hi Terry,
Basically you are not using the correct object loRodeo as the values. In the For loop you are creating an instance loRodeo for each record in the Me.EventEntriesRodeoBO1 and that is what you have to use, so change your code as follow:
If EventEntriesRodeoBO1.MoveFirst Then
For Each loRodeo As EventEntriesRodeoBO In Me.EventEntriesRodeoBO1.GetEnumerable
Select Case loRodeo.eventCD
Case "BB"
ContestantsRodeoBO1.EventBB = loRodeo.eventCD
Case "BR"
ContestantsRodeoBO1.EventBR = loRodeo.eventCD
End Select
Next
End If
ContestantsRodeoBO1.Save()ContestantsRodeoBO1.Save()
|
By Bill Cunnien - 4/6/2010
Wait...one other thing...
Select Case loRodeo.eventCD
Case "BB"
ContestantsRodeoBO1.Edit()
ContestantsRodeoBO1.EventBB = loRodeo.EventCD
ContestantsRodeoBO1.Save()
Case "BR"
etc.
|
By Edhy Rijo - 4/6/2010
Hi Bill,
There is no need to Edit/Save the BO in each case option. The BO will change its EditingState when you assign a value to any of its properties, then do one save out of the FOR loop.
|
By Bill Cunnien - 4/6/2010
Edhy beat me to the fix...good job!
|
By Bill Cunnien - 4/6/2010
There is no need to Edit/Save the BO in each case option. The BO will change its EditingState when you assign a value to any of its properties, then do one save out of the FOR loop.
Good to know...thanks!
|
By Edhy Rijo - 4/6/2010
Your are welcome Bill.
Terry, I just noticed that you are basically assigning loRodeo.eventCD to "BB" & "BR" events, if that is the case, you can simplify the code by using an IF..ENDIF or a single case "BB","BR" to speed up the process a bit if you need to.
|
By Terry Bottorff - 4/6/2010
WOW. Thanks for ALL the QUICK replies...... Let me get a grip on what you have replied and I will respond. Thanks again......
|
By Terry Bottorff - 4/6/2010
If EventEntriesRodeoBO1.MoveFirst Then
For Each loRodeo As EventEntriesRodeoBO In Me.EventEntriesRodeoBO1.GetEnumerable
Select Case loRodeo.eventCD
Case "BB"
ContestantsRodeoBO1.EventBB = loRodeo.eventCD
Case "BR"
ContestantsRodeoBO1.EventBR = loRodeo.eventCD
End Select
Next
End If
ContestantsRodeoBO1.Save()
I changed my code to the above but still no luck. I did get some info saved in 1 child record. Now the parent is moving but the child record is not? Can that happen? Do I somehow have to navigate to the child record? If so how come the toolbar on the form works?
Also, the relationship is 1 to 1 so I don't have to iterate thru more then 1 child record.
I once had a problem when a parent did not have any records in it so now I can check that with moving to the first record. I know I could use count but this is just something I do.
TIA.
|
By Terry Bottorff - 4/6/2010
Interesting. I moved the save() into the loop and it worked. Is that because the child table has been filtered with the parent child relationship and needs to get saved before the next filter? When it comes out of the loop would the child table be filtered and that is why I only got one record saved? I am looking to understand this.
Thanks again for all of the help.
|
By Edhy Rijo - 4/6/2010
Hi Terry,
You have to be very careful when using the BO.Filter since it may get you the wrong data.
If you have your relationship setup correctly, then you don't have to use the BO.Filter. If possible please post the whole code so we can have a better look at what you are doing. Saving the record inside the loop may not be the best approach based on how you are setting the whole scenario.
|
By Terry Bottorff - 4/7/2010
Sorry I have been so late on this but I have been working on another issue and finally resolved it.
Edhy this is all the code. Just in the click of a button and the parent child relationship set up on the form. If I move the Save inside the loop the data gets saved. If I move it out side the loop only the last data gets saved. When I was talking about filtering I was referring to SF's automatic filtering of the child records not me filtering anything.
If EventEntriesRodeoBO1.MoveFirst Then
For Each loRodeo As EventEntriesRodeoBO In Me.EventEntriesRodeoBO1.GetEnumerable
Select Case loRodeo.eventCD
Case "BB"
ContestantsRodeoBO1.EventBB = loRodeo.eventCD
Case "BR"
ContestantsRodeoBO1.EventBR = loRodeo.eventCD
Case "GB"
ContestantsRodeoBO1.EventGB = loRodeo.eventCD
Case "RB"
ContestantsRodeoBO1.EventRB = loRodeo.eventCD
Case "SR"
ContestantsRodeoBO1.EventSR = loRodeo.eventCD
Case "SW"
ContestantsRodeoBO1.EventSW = loRodeo.eventCD
Case "TD"
ContestantsRodeoBO1.EventTD = loRodeo.eventCD
Case "TR"
ContestantsRodeoBO1.EventTR = loRodeo.eventCD
End Select
' ContestantsRodeoBO1.Save()
Next
End If
' ContestantsRodeoBO1.Save()
|
By Terry Bottorff - 4/7/2010
As a follow up. Unless I put the following code after the For each lorodeo
Me.ContestantsRodeoBO1.FillByParentPrimaryKey(loRodeo.contestantId)
Nothing gets updated at all no matter where I put the save. Does that mean my parent child is not working? It does work on the form with the toolstrip.
|
By Edhy Rijo - 4/7/2010
Well it is not going to be easy to figure out without a sample, but the Me.EventEntriesRodeoBO1 BO should have been already filled and filtered using Me.ContestantsRodeoBO1.FillByParentPrimaryKey(loRodeo.contestantId) but again, that should not affect the FOR loop since.
Just to be clear, the child BO Me.EventEntriesRodeoBO1 should already have all the records related to the parent before going to the FOR loop. I usually put the FillByParentprimaryKey() in the Navigated event of the parent BO.
If still does not work, see if you can build a quick sample using the SF sample database. I have done that many times and in a more difficult way using the BO.Filter() which is very powerful and dangerous if you are not focus.
|
By Terry Bottorff - 4/8/2010
This Child BO is the ContestantsRodeoBO and the parent is the EventEntriesRodeoBO.
I was trying to put the Me.ContestantsRodeoBO1.FillByParentPrimaryKey(loRodeo.contestantId) in the navigated of the EventEntriesRodeoBO but of course it knows nothing about the object loRodeo. I tried a couple of other combinations but can not seem to get how to get all the references correct.
This was the last try but not working? Remember the parent is Event.... and the child is contestant......
Private Sub EventEntriesRodeoBO_Navigated(ByVal e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles MyBase.Navigated
ContestantsRodeoBO.FillByParentPrimaryKey(Me.contestantId)
End Sub
Thanks for any help.
|
By Bill Cunnien - 4/8/2010
Here's what I would do (C#, sorry):
foreach (EventEntriesRoderBO loRodeo in EventEntriesRodeoBO1.GetEnumerable())
{
. ContestantsRodeoBO loContestants = new ContestantsRodeoBO();
. loContestants.FillByParentPrimaryKey(loRodeo.contestantID);
. if (loContestants.Count > 0)
. {
. loContestants.Edit(); 'per Edhy, this is not necessary...just showing it for clarity
. switch (loRodeo.eventCD)
. {
. case "BB":
. loContestants.EventBB = loRodeo.eventCD;
. break;
. case ...
. }
. loContestants.Save();
. }
}
I find it a lot easier to manually handle the filling of child BOs. I often get lost in the automated attempts to do so.
Hope this helps,
Bill
|
By Bill Cunnien - 4/8/2010
If anyone knows how to get the code spacing/indentation to work properly, please let me know. I tried placing a period at the beginning of each line, but all of the spacing following it was whacked. Sorry for the poor indentation. Hope you can still read it.
|
By Greg McGuffey - 4/8/2010
I just use html non-breaking space code: ampersand nbsp;
Be sure to copy the content as these are removed if you preview the post.
I'd love to know if there is an easier way.
|
By Ivan George Borges - 4/8/2010
This is what I do:I usually just edit the code in a .txt file with Notepad Than I copy it from there to the browser If I want to copy code from VS I copy it to the .txt file too first And then copy it from there to the browser And this usually works fine Hope it helps
|
By Greg McGuffey - 4/8/2010
Hmmm....this didn't work for me. I typed in some text into notepad, selected all, copied into codesnippet (tried a quote too)...indentation was lost. You have some fancy-mancy notepad?
|
By Russell Scott Brown - 4/9/2010
I use Notepad++ which works well with various programming languages.You can download it (free) from: http://notepad-plus.sourceforge.net/uk/site.htm
|
By Ivan George Borges - 4/9/2010
Oh, never thought of that... I use Notepad2.exe (http://www.flos-freeware.ch/notepad2.html).It was recommended to me by Sir Steve Taylor.
|
By Greg McGuffey - 4/9/2010
I just tried out notepad2 and it's not keeping tabs/extra spaces either. Could there be some setting I'm missing? Or maybe this works with Vista/Win7 and not XP?
|
By Bill Cunnien - 4/9/2010
I went the notepad2 route, also. Here is my pasting of code from notepad2 which was originally from VS2k8:
public partial class Invoicing_Export : Aspire.UI.Windows.Forms.AspireBaseForm
{
public Invoicing_Export()
{
InitializeComponent();
}
}
How does that look?
|
By Bill Cunnien - 4/9/2010
Not so good... I am on W7 64bit.
public partial class Invoicing_Export : Aspire.UI.Windows.Forms.AspireBaseForm
{
public Invoicing_Export()
{
InitializeComponent();
}
}
This is the same code with the non-breaking spaces included.
|
By Bill Cunnien - 4/9/2010
Annoyingly pragmatic.
|
By Ivan George Borges - 4/9/2010
I can sell copies of mine... non-refundable.
|
By Greg McGuffey - 4/9/2010
Oh, I bet I know the diff. Yours is probably in Portuguese.
|
By Bill Cunnien - 4/9/2010
Narf!
|
By Terry Bottorff - 4/9/2010
I want to thank everyone for their help on my parent - child problem. It was great help and I learned a great deal. Thanks again I have it working and I understand how to do it next time.
|
By Trent L. Taylor - 4/12/2010
This is a great community out here. Thanks for all of your contributions!
|
By Greg McGuffey - 4/30/2010
Related to formatting code in the forum. I just found another method. Not as pretty as using Ivan's Portuguese Notepad2, but it saves having to use non-breaking spaces. just put <pre> tags just inside the codesnippet tags. This also doesn't completely fubar your formatting if you use preview.
//-- code just typed in via forum editor
public class BetterForumEditing : SF.WickedCoolEditor
public BetterForumEditing()
{
this.Property1 = "No reason to set this here...";
}
}
As you can see, it indents nicely, but there lines are spaces a bit far apart. Not sure which I like best: using non-breaking spaces, using the <pre> tag (which also works without codesnippet too) or learning Portuguese.
|