﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Updating grand child when saving parent (RegisterForeignKey)</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 14:06:24 GMT</lastBuildDate><ttl>20</ttl><item><title>Updating grand child when saving parent (RegisterForeignKey)</title><link>http://forum.strataframe.net/FindPost18089.aspx</link><description>Hi All,&lt;/P&gt;&lt;P&gt;I am having problem updating a grand child record when saving the parent.&amp;nbsp; I attached a small VB sample project using the SF Sample tables Customers, Orders and OrderItems.&lt;/P&gt;&lt;P&gt;I created the main form frmCustomers which is used to add Customer, then the orders are added via a ChildFormDialog frmOrders and the OrderItems are added programmatically, and here is the problem, when clicking the Save button in frmCustomers, the Customers and Orders records are saved and the or_Cust_PK is updated properly, but the record for OrderItems is not saved and I believe the problem is that the field orit_or_pk is not being updated with its parent field value.&lt;/P&gt;&lt;P&gt;To test do the following:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Add a new record in frmCustomers form (I added default values for all adding)&lt;/LI&gt;&lt;LI&gt;Add a new Order from the Order's listview toolbar.&lt;/LI&gt;&lt;LI&gt;Add a new Order Item from the frmOrders form.&amp;nbsp; (This will add a record programmatically with a orit_Prod_PK = 235)&lt;/LI&gt;&lt;LI&gt;Click OK in frmOrders form.&lt;/LI&gt;&lt;LI&gt;Click the Save button in the frmCustomers toolbar.&lt;/LI&gt;&lt;LI&gt;In the Orders listview, Edit the Test PO record.&lt;/LI&gt;&lt;LI&gt;Notice that there is no Order Item record created, and I have not been able to find out why.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Notice that all I am trying to do here is to implement the logic of saving all BOs in at a single point, in this case the frmCustomers form's Save button.</description><pubDate>Wed, 30 Jul 2008 09:02:00 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Updating grand child when saving parent (RegisterForeignKey)</title><link>http://forum.strataframe.net/FindPost18216.aspx</link><description>Good to hear! :)</description><pubDate>Wed, 30 Jul 2008 09:02:00 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Updating grand child when saving parent (RegisterForeignKey)</title><link>http://forum.strataframe.net/FindPost18215.aspx</link><description>Hi Dustin,&lt;/P&gt;&lt;P&gt;Just to let you know that using FillMultipleDataTables&amp;nbsp;worked, and not only that, it minimized the amount of code I used before.</description><pubDate>Wed, 30 Jul 2008 07:54:46 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Updating grand child when saving parent (RegisterForeignKey)</title><link>http://forum.strataframe.net/FindPost18152.aspx</link><description>I suspected as such, sounds good. FYI -There are multiple examples of FillMultipleDataTables in the maintenance forms of the StrataFlix sample, as well as how we utilize the browse on maintenance forms. &lt;br&gt;
&lt;br&gt;
Good luck! :)</description><pubDate>Mon, 28 Jul 2008 16:59:30 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item><item><title>RE: Updating grand child when saving parent (RegisterForeignKey)</title><link>http://forum.strataframe.net/FindPost18151.aspx</link><description>Hi Dustin,&lt;/P&gt;&lt;P&gt;Thanks for taking the time to review the sample project.&amp;nbsp; I will review your post in detail and make the changes in the sample project before changing my project.&lt;/P&gt;&lt;P&gt;I have not used the FillMultipleDataTable, and guess it is now time to start using it.&amp;nbsp; In my project I use a Browse Dialog in the main form, but due to time to create the sample project I when the easiest way by just selecting TOP 100.&amp;nbsp; From my quick review, I noticed the main cause was the filtering of the order item table, which after you explained it, makes perfect sense.</description><pubDate>Mon, 28 Jul 2008 16:52:00 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Updating grand child when saving parent (RegisterForeignKey)</title><link>http://forum.strataframe.net/FindPost18146.aspx</link><description>You're close!&amp;nbsp;Your BOs and relationships are set up correctly, you just have a couple small&amp;nbsp;issues on&amp;nbsp;populating the BOs and&amp;nbsp;programatically creating that record&amp;nbsp;:w00t:.&lt;P&gt;The reason your orderitems aren't getting saved is that you are doing a FillByParentPrimaryKey in the Navigated event of the orders business object. This event gets fired when you return from the Orders child form. As a result, any changes to your OrdersItems business object were getting overwritten once you returned to the parent form.&lt;/P&gt;&lt;P&gt;Rather than loading the orders and order items in seperate queries (which requires a server trip every time you click an item in the orders list), I'd recommend you do a FillMultipleDataTables whenever you pick the customer you want to work with, and then just filter BizOrderItems1 down to the pertinate records on the navigate of BizOrders1. In effect, BizOrderItems1 will contain [i]all[/i] orderitems&amp;nbsp;records for [i]all[/i] orders associated with the selected customer but, due to the filter, will only [i]show[/i] the orderitems for the currently selected order. This would be a much more efficient approach in terms of server trips, and has the added benifit of not clearing out your grandchild BO every time the child&amp;nbsp;BO navigates ;).&lt;/P&gt;&lt;P&gt;You would call FillMultipleDataTables on the BizCustomers1 navigated event of the Customers form to make it work as it stands. &lt;/P&gt;&lt;P&gt;[codesnippet]&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub BizCustomers1_Navigated(ByVal e As MicroFour.StrataFrame.Business.NavigatedEventArgs) Handles BizCustomers1.Navigated&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Get all Orders for the current Customer.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If BizCustomers1.Count &amp;gt; 0 AndAlso BizCustomers1.Then &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Call FillMultipleDataTables here&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lvOrders.Requery()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub[/codesnippet]&lt;/P&gt;&lt;P&gt;[b]Note:[/b] The above is how to make it work in your existing form, but it isn't how we would typically do it. From a form-design standpoint, we don't typically&amp;nbsp;load a bunch of records and then use forward and back buttons&amp;nbsp;to navigate through them. Instead, we typically call a browse, pick the [i]specific[/i] customer record to work with, and then call FillMultipleDataTables upon the return of the browse form. &lt;/P&gt;&lt;P&gt;That will keep your order items from being overwritten. To get them to actually [i]save[/i], you'll need to address a couple of things when you programatically create the record. You would have seen and corrected these yourself, I'm sure, but since I was already in there, I thought I would point them out :).&lt;/P&gt;&lt;P&gt;On the orders form, change this:&lt;/P&gt;&lt;P&gt;[codesnippet]&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub cmdAddToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddToolStripMenuItem.Click&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.BizOrderItems1.NewRow()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.BizOrderItems1.orit_or_pk = Me.BizOrders1.or_pk&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.BizOrderItems1.orit_prod_pk = 235&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.lvOrderItems.Requery()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub[/codesnippet]&lt;/P&gt;&lt;P&gt;To this:&lt;/P&gt;&lt;P&gt;[codesnippet]&amp;nbsp;&amp;nbsp;&amp;nbsp; Private Sub cmdAddToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddToolStripMenuItem.Click&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.BizOrderItems1.NewRow()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.BizOrderItems1.orit_or_pk = Me.BizOrders1.or_pk&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.BizOrderItems1.orit_prod_pk = 1&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.lvOrderItems.Requery()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Sub[/codesnippet]&lt;/P&gt;&lt;P&gt;Basically, you don't need to set the orderitems primary key (it does it for you), but you do need to specify a valid product id (in production, you'll likely need some kind of user input rather than hardcoding a specific product.) &lt;/P&gt;&lt;P&gt;Hope it helps!&amp;nbsp;:D</description><pubDate>Mon, 28 Jul 2008 15:55:03 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item></channel></rss>