October 1, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Building an ASP.NET 2.0 Master/Detail Application With DB2

  • October 13, 2006
  • By Anil Mahadev
  • Send Email »
  • More Articles »

Back in the old days, connecting two data grids to enable master/detail relationships wasn't that easy. Now with Visual Studio 2005 and ASP.NET 2.0, building master/detail relationship apps is just a matter of using the right controls for the job. This tutorial describes using DB2 with ASP.NET 2.0's master/detail relationship enhancements. The intention is to help you leverage the latest features of Visual Studio 2005 to make data-driven Web application development a breeze.

You will learn how to build a master/detail application quickly using the grid view and details view controls—and writing little or no code. The example application uses a typical HR scenario: determining and displaying the employees who belong to a particular department.

A basic knowledge of VS 2005 and ASP.NET 2.0 is necessary to complete the tutorial, as are the following system and software requirements:

  • A basic P4 Machine with 512 MB RAM and about 20 GB HDD space
  • Windows 2000 and above
  • A personal copy of DB2 UDB (You can download DB2 Express-C Edition for free, but any edition will do.)
  • Microsoft Visual Studio.NET 2005 (Professional or Team System)
  • An install of the DB2 Add-in and Data Provider for .NET 2.0, once you have completed the installation of DB2 UDB

Example Application

To begin building the example master/detail application, create an employee (EMP) table and a department (DEPT) table. You can reuse the SAMPLE Database for creating these tables. The following are the structures for each:

EMP Table
 
-- DDL Statements for table "ANIL    "."EMP"
------------------------------------------------

 
CREATE TABLE "ANIL    "."EMP"  (
                     "EMPNO" CHAR(10) NOT NULL , 
                     "ENAME" VARCHAR(40) , 
                     "DEPTNO" CHAR(10) , 
                     "SALARY" DECIMAL(10,2) , 
                     "EMAIL" VARCHAR(50) )   
                    COMPRESS YES  
                    IN "USERSPACE1" ; 
 
 
-- DDL Statements for primary key on Table "ANIL    "."EMP"
 
ALTER TABLE "ANIL    "."EMP" 
          ADD CONSTRAINT "PK_EMPNO" PRIMARY KEY
                   ("EMPNO");
 
DEPT Table
 
-- DDL Statements for table "ANIL    "."DEPT"
------------------------------------------------

 
CREATE TABLE "ANIL    "."DEPT"  (
                     "DEPTNO" CHAR(10) NOT NULL , 
                     "DNAME" VARCHAR(50) , 
                     "LOCATION" VARCHAR(10) )   
                    IN "USERSPACE1" ; 
 
 
-- DDL Statements for primary key on Table "ANIL    "."DEPT"
 
ALTER TABLE "ANIL    "."DEPT" 
          ADD CONSTRAINT "PK_DEPTNO" PRIMARY KEY
                   ("DEPTNO");

Next, run the following script to enable primary and foreign key relationships between the two tables:

-- DDL Statements for primary key on Table "ANIL    "."EMP"
 
ALTER TABLE "ANIL    "."EMP" 
     ADD CONSTRAINT "PK_EMPNO" PRIMARY KEY
              ("EMPNO");
 

Now that the tables are ready, you can insert some valid data. The DEPT table will have four departments consisting of DEPTNO ranges from 10, 20, 30, and 40, respectively. The department names will be IT, Mktng, Finance, and HR. For the EMP table, make sure that you enter the correct DEPTNO for a particular employee to maintain referential integrity.

Once you have done that, you can visually build your master/detail application in Visual Studio 2005. You may run the SQL statements for the DEPT and EMP tables in the Command Editor and change the schema from ANIL to anything you choose.





Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel