DataSet.Relations 属性 获取用于将表链接起来并允许从父表浏览到子表的关系的集合。 [Visual Basic] Public ReadOnly Property Relations As DataRelationCollection [C#] public DataRelationCollection Relations {get;} [C++] public: __property DataRelationCollection* get_Relations(); [JScript] public function get Relations() : DataRelationCollection; 属性值 包含 DataRelation 对象的集合的 DataRelationCollection;否则为空值(如果不存在任何 DataRelation 对象)。 示例 [Visual Basic] 以下示例通过 Relations 属性打印所有子表的列名。 [Visual Basic] Private Sub PrintChildRelationRows() ' Declare variable to hold the row values. Dim strRowVals As String Dim myDataSet As DataSet ' Get the DataSet of a DataGrid that is displaying data of at least two ' tables. Dim myTable As DataTable = CType(DataGrid1.DataSource, DataTable) ' Navigate using the Relations. Dim myRel As DataRelation Dim row As DataRow Dim col As DataColumn ' Print the names of each column in each table through the Relations. For Each myRel In myDataSet.Relations For Each col in myRel.ChildTable.Columns strRowVals &= col.ColumnName & " " Next Next ' Display results. Console.WriteLine(strRowVals) End Sub
DataColumn parentCol; DataColumn childCol; // Code to get the DataSet not shown here. parentCol = DataSet1.Tables["Customers"].Columns["CustID"]; childCol = DataSet1.Tables["Orders"].Columns["CustID"]; // Create DataRelation. DataRelation relCustOrder; relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol); // Add the relation to the DataSet. DataSet1.Relations.Add(relCustOrder);
获取用于将表链接起来并允许从父表浏览到子表的关系的集合。
[Visual Basic]
Public ReadOnly Property Relations As DataRelationCollection
[C#]
public DataRelationCollection Relations {get;}
[C++]
public: __property DataRelationCollection* get_Relations();
[JScript]
public function get Relations() : DataRelationCollection;
属性值
包含 DataRelation 对象的集合的 DataRelationCollection;否则为空值(如果不存在任何 DataRelation 对象)。
示例
[Visual Basic] 以下示例通过 Relations 属性打印所有子表的列名。
[Visual Basic]
Private Sub PrintChildRelationRows()
' Declare variable to hold the row values.
Dim strRowVals As String
Dim myDataSet As DataSet
' Get the DataSet of a DataGrid that is displaying data of at least two
' tables.
Dim myTable As DataTable = CType(DataGrid1.DataSource, DataTable)
' Navigate using the Relations.
Dim myRel As DataRelation
Dim row As DataRow
Dim col As DataColumn
' Print the names of each column in each table through the Relations.
For Each myRel In myDataSet.Relations
For Each col in myRel.ChildTable.Columns
strRowVals &= col.ColumnName & " "
Next
Next
' Display results.
Console.WriteLine(strRowVals)
End Sub
DataColumn childCol;
// Code to get the DataSet not shown here.
parentCol = DataSet1.Tables["Customers"].Columns["CustID"];
childCol = DataSet1.Tables["Orders"].Columns["CustID"];
// Create DataRelation.
DataRelation relCustOrder;
relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol);
// Add the relation to the DataSet.
DataSet1.Relations.Add(relCustOrder);
有没有更详细的说明啊?
感谢simon8181() 、LoveCherry(最讨厌你们这些要代码的了,一点技术含量都没有)、wangrenda(浪人) 和其他支持关心的,我有一点点明白了,但还不是很清晰