Published: Tuesday, February 08, 2000
Displaying Parent/Child Database Relationships through an ASP Page
By Syed Armoghan Qadir Shah
As the Internet grows the need for dynamic data grows. I looked at several techniques on how display data
using ASP and HTML. None of the techniques satisfied my needs. I wanted to look at my data over the Internet
in Master/Detail fashion.
In Relational data bases you can relate to pieces of your data. Like the Parent/Child relationship where, say
there is a Customer table and an Orders table, you want to find orders
relating to a particular customer. To setup such a relationship,
the primary key in Customer table would be a foreign key in the Orders table.
This key will pull down information from the data base.
A Master/Detail relationship is the same concept. Let us talk about the Northwind Database. In that database
there is an Orders table, If the user wants to see the related records in the
Order Details table they would be displayed based on OrderID key which will
establish a relationship between the two tables.
What I wanted to do was to be able to display a list of orders from the Orders table, having
each record provide a hyperlink, that, if clicked, would display that particular order's entry from the
Order Details table.
I looked at an ASP-DB solution but that was too sophisticated for my needs.
Therefore, I decided to write my own program to help my users look at order details over the Intranet and
internet. I got help from Microsoft in this project and the end result I want to share with you all. In the
past I have definitely benefited from articles from 4Guys. This article is the first part of a three part
series.
In the second part I will show how to link two details
with one Master Record. In the third and final part I will utilize ADO Data Shaping techniques to effectively
query and Page through Recordsets. (To learn more about data shaping, be sure to read:
Data Shaping and Advanced Data Shaping Techniques.)
In my code example in this article I will use the Northwind database which ships with Microsoft Office.
Below you can see a quick ER diagram of the Northwind tables I will be using:
| Orders |
| OrderID | Autonumber |
| CustomerID | Number |
| OrderDate | Date/Time |
| ShipName | Text |
| ... More irrelevant fields ... |
| Order Details |
| OrderID | Number |
| ProductID | Number |
| UnitPrice | Currency |
| Quantity | Number |
| Discount | Number |
Another thing I will be displaying in this article would be how to use multiple recordsets using ADO and how
to effectively sort and search records.
The system contains two pages, Master.asp and Detail.asp.
The code for these two pages are too lengthy to post in this article, but there are links to the source code
and to an on-line demo at the bottom of this page. You can also
demo the code presented in this article.
If you click on the OrderID field on the master page (Master.asp) it will show you
that particular order's details (Detail.asp).
I believe that my solution proves to be much simpler than using expensive solutions; furthermore, with my
solution the
has more control on what information to display. With a little modification to these scripts you can use this
code for your own projects!
For feedback please email me at Armoshah@hotmail.com.
Attachments:
Download the source code for Master.asp in text format
Download the source code for Detail.asp in text format
Test out the application!
About the Author:
My name is Syed Armoghan Qadir Shah. I am consultant with Infoexperts.
I am consulting for a company called Sei Incentives, Ltd. SEI is based in Irving Texas. In the past I have done
work with EDS as a Data Warehouse programmer.
I have done my MBA with MIS as a Major from University of Dallas in Irving TX.
My skill set includes Visual Basic, ASP, HTML, SQL Server, Java and MS Access. I started doing web pages as a
hobby and then developed immense interest in ASP using ADO and VB Script. This is one of my many solutions I
developed for one of my clients. I benefited a lot from web sites like 4GuysFromRolla.com
and ASPtoday.com and wanted to contribute something useful. I saw a lot
of postings on the ASP Messageboard about dynamic data bases but
solutions to these were either pretty intricate or expensive.
Some of the sites I have worked on are www.infoexpertsusa.com,
www.sei-incentives.com and www.ultratraders.com.
It is my philosophy to make complex coding techniques fairly simple. I further believe that writing computer
code is an art and not a science. I can be reached at Armoshah@hotmail.com.
Happy Programming!