This topic is locked
[SOLVED]

 Adding a record to one table and displaying data from a related table

3/11/2016 10:38:40 AM
ASPRunner.NET General questions
Pete K author

How would you handle this situation? I have two related tables, Offering (classes to enroll in) and Enrollment, which contains userids and offeringids (related to Offering table). So, when having users enroll, I am naturally using the enrollment/add page. But I would like to display some data from the offering table (class name, location, dates, etc.) as a visual reminder of what they are signing up for and to have access to the data for the confirmation email.
What's the best way to accomplish this?

Sergey Kornilov admin 3/11/2016

If these two table are related as master-details you can choose to display details table info on Add/Edit/View pages of the master record. You can turn on this option in master-details relationship properties on 'Datasource tables' screen.

jadachDevClub member 3/12/2016

Another option is to join the enrollment table to your existing offering table in the sql editor (outer join). Then display those values as read only on add/edit pages.

This works fine when it's a 1 to 1 relation. If it's one to many, either do what Sergey said or do what I said by preparing a view in your database to handle what you want in order to make it 1 to 1.

Pete K author 3/14/2016

Thanks for the helpful replies.
Unfortunately, I can't get any of those methods suggested above to achieve what I want. It might not be possible without coding. After giving it some thought, I think I'm approaching it wrong. Help me think this through.
So, the table I want to add a new record to (Enrollment) is on the many side of the join with the table I want to get related information from (Offering). So what I am trying to do is add to the details table and show the master table. There doesn't seem to be a way to use Sergey's method to do this in the GUI -- so that's out.
Looking at Jerry's suggestions, I still can't figure out how to get it to work when I'm trying to add a record to a table that is in a many-to-one relationship with the table form which I want to pull data. It seems I should be passing the OfferingID value as passed from the calling page to the query before the page renders, but on an add page I wouldn't think a select query would run anyway. Sorry, but I'm just having a hard time wrapping my brain around this. I just don't think this is possible without coding.

jadachDevClub member 3/14/2016

Can you post your 2 table structures? I think there is a way, just not 100% following you. I'd like to try myself.

Pete K author 3/15/2016

Absolutely. I'd love to see what you can come up with, Jerry. Very much appreciate your taking a crack at it.
My link
The above link is a snapshot of the two tables. As you can see, Enrollment is related to Offering in a many-to-one relationship on OfferingID = Enrollment.Offering. To reiterate what I'm trying to do, I want to create a user-friendly signup page, which would be an Enrollment/add type page. But I want to display selected information for the Offering they are signing up for (e.g., Title, Location, etc.) from the Offering table. The only two fields in Enrollment that get populated from the app at enrollment time are Learner (UserID, from a session variable) and Offering (passed as a query string from the calling page).
Any ideas appreciated!

jadachDevClub member 3/15/2016

So I started thinking about this and contemplated the way I would approach it. I would be inclined to have users go to the offerings list page. There they can search, see more info, etc. I would then add a custom enroll button on each record of this list page. By clicking the button, it would insert relevant data into the enrollment table then redirect to my enrollment that will show all offerings that user enrolled in. They could then edit or delete from there. Does that make any sense at all to you? Am I understanding what you want to acheive?

Pete K author 3/16/2016

Yes, you are understanding it perfectly and that's exactly how I am implementing it, except that the folks I am working for really want to present the user with visual confirmation that they are in fact signing up for the offering they intended to pick, before they click the final enroll button. So I was thinking about how I have handled similar situations in Iron Speed and I think I have a workable solution, but I'm not sure how to implement it in ASPR.
I would like to add event code to the (Before display?) event which would take the OfferingID which was passed via querystring and retrieve the appropriate record from the Offering table and populate some generic text boxes with that data. Seems simple enough but I'm not sure how to write the code. It seems documentation and examples are sparse in the help file.

jadachDevClub member 3/16/2016

Check your email.