General information
Category:
Forms & Form designer
>>I am trying to create a simple parent/child relationship on a data-entry form.
>>Should I be using a view of the parent table AND a view of the child table in the dataenvironment, or should I be using one view of the two tables combined??? Since views dont have indexes like tables, how do I specify the relationship between the parent/child views???
>>
>Martin, I'd use one view with data for both the parent and the child. If your grid is showing JUST the data for a single parent record (such as showing contacts for a given company) you should use a parameterized view.
>
>Your grid will link the parent to the child by the parent's primary key, which should be the child's foreign key. The resulting SQL would look like:
>
>SELECT parent.company, parent.address, child.name, child.phone;
> FROM parent, child;
> WHERE parent.IDCODE = child.IDCODE;
> INTO cursor VUTEMP;
> ORDER by COMPANY
Thanks for the tip Barbara. I now have a form with the parent table's fields and a grid containing the child rows.
If you have a moment, I have a few more questions:-
Am I right in thinking that the SQL you gave as an example is that generated by the view definition? Or do you mean I should be hardcoding the SQL statement somewhere?
How do I add records to the child table? The Tastrade example used a right-click popup-menu which ran some code to append a blank child record, set it's key to that of the parent's primary, and then setfocus to the grid line.
If I try this with the parent/child view, APPEND BLANK is going to insert a row to the parent table as well as the child table.
After setting the primary key of this blank row, the TABLEUPDATE fails with error 1884 - duplicate primary key.
Is there a way I can use this combined view to create new primary table rows AND/OR new child table rows?
Martin
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only