首先,建立一个Relations并将它添加到DataSet中:
Dim dcCustomerCustID As DataColumn
Dim dcOrdersCustID As DataColumn
dcCustomerCustID = myDataSet.Tables("custTest").Columns("custID")
dcOrdersCustID = myDataSet.Tables("orderTest").Columns("custID")
Dim relCustomerOrders As DataRelation
relCustomerOrders = New DataRelation("CustomerOrders", dcCustomerCustID, dcOrdersCustID)
myDataSet.Relations.Add(relCustomerOrders)
然后,建立新的DataColumn,使用DataColumn的Expression属性得到父表(Parent Talbe)中的值,再将这些DataColumn添加到子表(Child Table)中:
Dim oCustName As DataColumn
oCustName = New DataColumn()
oCustName.DataType = System.Type.GetType("System.String")
oCustName.ColumnName = "custName"
oCustName.Expression = "Parent.custName"
myDataSet.Tables("orderTest").Columns.Add(oCustName)
接着,设定DataView,将DataGrid与子表绑定:
Dim dv As DataView
dv = New DataView(myDataSet.Tables("orderTest"))
DataGrid1.DataSource = dv
这样,就可以使用一个DataGrid显示两个Table中的数据了。
有关DataColumn的Expression属性,请参考MSDN中相应的内容:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataColumnClassExpressionTopic.asp
posted on 2005-10-28 14:31
萌芽的叶子 阅读(572)
评论(0) 编辑 收藏 引用 所属分类:
sql