Question Adding datacolumn using expression

karthimca07

New member
Joined
Nov 24, 2011
Messages
1
Programming Experience
1-3
Hi,
I have a dataset of two datatables with parent and child relation defined.

Now i want to add a column into child table from parent table?

look at the below code i tried. i got the error saying column name not found

Please help me

VB.NET:
Dim DtCompany As New DataTable()
                DtCompany = db.GET_TABLE("select mc_id,mc_name from med_Company")
                DtCompany.DataSet.Tables.Remove(DtCompany)
                DtCompany.TableName = "Comp"
                DsTrans.Tables.Add(DtCompany)
                Dim RelComp As New DataRelation("COMPREL", DtCompany.Columns("mc_id"),      DsTrans.Tables(0).Columns("mss_compid"))
                DsTrans.Tables("table").Columns.Add("Company", GetType(String), "Comp.mc_name")
                grdDetails.DataSource = DsTrans
 
All you need to do, as is usually the case, is read the documentation. This is the relevant excerpt from the MSDN topic for the DataColumn.Expression property:
Parent/Child Relation Referencing
A parent table may be referenced in an expression by prepending the column name with Parent. For example, the Parent.Price references the parent table's column named Price.

When a child has more than one parent row, use Parent(RelationName).ColumnName. For example, the Parent(RelationName).Price references the parent table’s column named Price via the relation.

A column in a child table may be referenced in an expression by prepending the column name with Child. However, because child relationships may return multiple rows, you must include the reference to the child column in an aggregate function. For example, Sum(Child.Price) would return the sum of the column named Price in the child table.

If a table has more than one child, the syntax is: Child(RelationName). For example, if a table has two child tables named Customers and Orders, and the DataRelation object is named Customers2Orders, the reference would be as follows:

Avg(Child(Customers2Orders).Quantity)
 
Back
Top