﻿<?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 » WinForms (How do I?)  » Problem with 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 09:06:05 GMT</lastBuildDate><ttl>20</ttl><item><title>Problem with RegisterForeignKey()</title><link>http://forum.strataframe.net/FindPost20367.aspx</link><description>&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;&lt;STRONG&gt;&lt;FONT color=#000000&gt;Hi Trent,&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;&lt;STRONG&gt;&lt;FONT color=#000000&gt;I have the following tables:&lt;BR&gt;&amp;nbsp; 1.&amp;nbsp;Company (Parent)&lt;BR&gt;&amp;nbsp; 2.&amp;nbsp;MemberInfo (Parent)&lt;BR&gt;&amp;nbsp; 3.&amp;nbsp;Address Mem(Child to 1 and 2 above)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;STRONG&gt;In the AddressMemBO I have a relationship define for the MemberInfo (put the relation info here) I have a form where I want to use AddressMemBO related to Company so the correct AddressMemBO.Company_FK) can be updated automatically, I am trying to use the BO.RegisterForeingKey method to archive this with the following code:&lt;BR&gt;&lt;BR&gt;[codesnippet]&lt;BR&gt;Private Sub CompanyBO1_ParentFormLoading() Handles CompanyBO1.ParentFormLoading&lt;BR&gt;&amp;nbsp;Me.CompanyBO1.RegisterForeignKey(Me.AddressMemBO1, "Company_FK")&lt;BR&gt;&amp;nbsp;Me.CompanyBO1.FillAllRecords()&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;STRONG&gt;&amp;nbsp;If Me.CompanyBO1.Count &amp;gt; 0 Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;Me.AddressMemBO1.FillByParentPrimaryKey(Me.CompanyBO1.Company_PK)&lt;BR&gt;&amp;nbsp;End If&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;STRONG&gt;&amp;nbsp;Me.lstAddress.Requery()&lt;BR&gt;End Sub&lt;BR&gt;[/codesnippet]&lt;BR&gt;&lt;BR&gt;The above code is not working, the BO.FillByParentPrimaryKey() is not returning any record, where I am sure there are related records in the database, also when adding a new AddressMem record, the Company_FK is not being updated.&lt;BR&gt;&lt;BR&gt;Now if I change in the AddressMemBO class&amp;nbsp;relationship via&amp;nbsp;the class&amp;nbsp;to it will&amp;nbsp;be with Company table instead of MemberInfo, it will work just fine. (One relation at the time).&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;STRONG&gt;So what am I&amp;nbsp;missing in the use of BO.RegisterForeingKey?&lt;BR&gt;&lt;BR&gt;Thanks,&lt;BR&gt;&lt;BR&gt;Doron&lt;BR&gt;&lt;/P&gt;&lt;/STRONG&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt -0.5in"&gt;The&amp;nbsp;&lt;BR&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/SPAN&gt;</description><pubDate>Sat, 01 Nov 2008 17:02:51 GMT</pubDate><dc:creator>Doron Farber</dc:creator></item><item><title>RE: Problem with RegisterForeignKey()</title><link>http://forum.strataframe.net/FindPost20507.aspx</link><description>Hi Trent,&lt;P&gt;I hope you will get to it&amp;nbsp;sometimes soon.:)&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Doron</description><pubDate>Sat, 01 Nov 2008 17:02:51 GMT</pubDate><dc:creator>Doron Farber</dc:creator></item><item><title>RE: Problem with RegisterForeignKey()</title><link>http://forum.strataframe.net/FindPost20502.aspx</link><description>That may be a possibility.&amp;nbsp; But one reason that we will always have the code mechanism is because it allows you to setup temp relationships, etc. that may not be permamnent or necessary most of the time.&amp;nbsp; But I understand your point.</description><pubDate>Sat, 01 Nov 2008 10:28:08 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Problem with RegisterForeignKey()</title><link>http://forum.strataframe.net/FindPost20489.aspx</link><description>Hi Trent,&lt;P&gt;Your suggestion worked just fine. But it will be nice if I can use the wizard to add un limited relations instead of adding the relation by code. Is that on the work for the next version?:cool:&amp;nbsp; In a way this is&amp;nbsp;like small DD where the relation is defined and it is easier to see or manage all relations with this little&amp;nbsp;graphical interface. &lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Doron</description><pubDate>Fri, 31 Oct 2008 13:26:47 GMT</pubDate><dc:creator>Doron Farber</dc:creator></item><item><title>RE: Problem with RegisterForeignKey()</title><link>http://forum.strataframe.net/FindPost20371.aspx</link><description>The RegisterForeignKey is used for updates, not queries.&amp;nbsp; In order to rely on the FIllByParentPrimaryKey method, you must define the relationship thorugh the ParentRelationship property.&amp;nbsp; If this is already defined elsewhere, then just create a Fill method that accepts two parms: foreignKeyPk and the AddressType (i.e. company, customer, etc.).&amp;nbsp; Generally we will create an enum for a type field.&amp;nbsp; An example of this in our medical software is phone numbers.&amp;nbsp;&amp;nbsp;We have a single PhoneNumbers table that is used for every entity in the applicaiton that may need a phone number (i.e. patients, insurance carriers, doctors, etc.).&amp;nbsp; So we have a fill method that looks something like this on the PhoneNumbersBO:&lt;/P&gt;&lt;P&gt;[codesnippet]Public Sub FillAll(ByVal parentPk As Long, ByVal parentType As AddressType)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Establish Locals&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim cmd as New SqlCommand("SELECT * FROM Addresses WHERE ad_fk_parent = @parentPk AND ad_Type = @parentType")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Create the parms&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd.Parameters.Add("@parentPk", SqlDbType.BigInt).Value = parentPk&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmd.Parameters.Add("@parentType", SqlDbType.Int).Value = parentType&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Populate the BO&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.FillDataTable(cmd)&lt;/P&gt;&lt;P&gt;End Sub[/codesnippet]</description><pubDate>Mon, 27 Oct 2008 09:09:29 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>