• DataSet.Relations 属性


    获取用于将表链接起来并允许从父表浏览到子表的关系的集合。
    属性值
    包含 DataRelation 对象的集合的 DataRelationCollection;否则为空值(如果不存在任何 DataRelation 对象)。

    [Visual Basic]
    Public ReadOnly Property Relations As DataRelationCollection

    [C#]
    public DataRelationCollection Relations {get;}


    示例
    [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


    又一个例子:
                //ADOSample3\form.cs
                private void button1_Click(object sender, System.EventArgs e)
                
    {
                    
    //create a dataset
                    DataSet ds=new DataSet("XMLProducts");
                    
    //connect to the northwind database and 
                    
    //select all of the rows from products table and from suppliers table
                    
    //make sure you connect string matches you server configuration
                    
                    
    string source = Login.Connection;
                    
                    SqlConnection conn
    =new SqlConnection(source);
                    
                    SqlDataAdapter daProd
    =new SqlDataAdapter("SELECT * FROM Products",conn);
                    SqlDataAdapter daSup
    =new SqlDataAdapter("SELECT * FROM Suppliers",conn);
                    
    //Fill DataSet from both SqlAdapters
                    daProd.Fill(ds,"products");
                    daSup.Fill(ds,
    "suppliers");
                    
    //Add the relation
                    ds.Relations.Add(ds.Tables["suppliers"].Columns["SupplierId"],
                        ds.Tables[
    "products"].Columns["SupplierId"]);
                    
    //Write the Xml to a file so we can look at it later
                    ds.WriteXml("..\\SuppProd.xml",XmlWriteMode.WriteSchema);
                    
    //load data into grid
                    dataGrid1.DataSource=ds;
                    dataGrid1.DataMember
    ="suppliers";
                    
    //create the XmlDataDocument
                    doc=new XmlDataDocument(ds);
                    
    //Select the productname elements and load them in the grid
                    XmlNodeList nodeLst=doc.SelectNodes("//ProductName");
         
                    
    foreach(XmlNode nd in nodeLst)
                        listBox1.Items.Add(nd.InnerXml);
        
                }

  • 相关阅读:
    线程的简单介绍
    队列Joinablequeue的使用,以及生产者消费者模型的认识
    使用子线程来完成链接循环和通信循环
    使用socketserver实现简单的下载和上传
    类的绑定方法学习
    类的组合-多态-封装等特性的简单学习
    爬虫之亚马逊爬取
    JavaScript 面试中常见算法问题详解
    JavaScript 的 this 指向问题深度解析
    深入理解 JavaScript 中的函数
  • 原文地址:https://www.cnblogs.com/myx/p/87400.html
Copyright © 2020-2023  润新知