Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Calculated columns that refer to relationships

Total Hit ( 2990)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The DataSet is a container of multiple DataTables, and it allows to create parent-child relationships between two tables, as shown below:

Click here to copy the following block
' create a relationship between the Categories and the Products tables,
' against the CatID column
ds.Relations.Add(New DataRelation("CatProducts", _
  ds.Tables("Categories").Columns("CatID"), ds.Tables("Products").Columns _
  ("CatID")))

This is nice, but even nicer is the possibility to create calculated columns in a table, that refer to the parent-child relationship. For example, here's how you can create a new column ProductsCount in the DataSet's Categories table, which will return the number of child products:

Click here to copy the following block
' add a new calculated column to the Categories table, with the number of child
' products
ds.Tables("Categories").Columns.Add("ProductsCount", GetType(Integer), _
  "Count(Child(CatProducts).ProductID)")

The expression refers to the CatProducts relationship created before, and uses the Count function to count the number of child records returned by the relationship for each single category. Many aggregate functions are supported, such as Min, Max, Sum, Avg.
From a child record, you can also refer to the parent item of course. The following code shows how to add a calculated column to the Products table, that will contain the name of the parent category:

Click here to copy the following block
' add a new calculated column to the Products table,
' with the name of the parent category
ds.Tables("Products").Columns.Add("CategoryName", GetType(String), _
  "Parent(CatProducts).CategoryName")


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.