//Master Table with Primary key “ProductId”
dtGridTable.TableName = “StockRotationAlg”
//Child Table with Primary key “ProductId, TxnType”
dtChildGridTable.TableName = “ChildTable”
//dataset name srDataset
srDataSet.Tables.Add(dtGridTable)
srDataSet.Tables.Add(dtChildGridTable)
ParentColumn = dtGridTable.Columns(“ProductId”)
ChildColumn = dtChildGridTable.Columns(“ProductId”)
//Foreign key Constraint
FKC = New ForeignKeyConstraint(“StockRotationAlgFKC”, ParentColumn, ChildColumn)
dtChildGridTable.Constraints.Add(FKC)
FKC.DeleteRule = Rule.Cascade
FKC.UpdateRule = Rule.Cascade
FKC.AcceptRejectRule = AcceptRejectRule.None
//Data relation
dataRelation = New dataRelation(“StockRotationAlgFKC”, ParentColumn, ChildColumn, False)
srDataSet.Relations.Add(dataRelation)
//
//IMP. With the above code I can able to bind to datagrid(Microsoft default grid).
// I am able to create relation and I can able to see the child table link.
//
//And I am binding the dataset to both master and child as
dgStockRotation.DataSource = srDataSet
dgStockRotation.DataMember = “StockRotationAlg”
dgChildTable.DataSource = srDataSet
dgChildTable.DataMember = “StockRotationAlg.StockRotationAlgFKC”
// Now I can able to see only parent (Master) table. Child table is shown as blank.
// I found the same code with your example.
// If any thing wrong or modification please inform to me.
Imported from legacy forums. Posted by Sivaram (had 1944 views)