// 创建 Authors 表和 Titles 表之间的关系.
  ds.Relations.Add("myrelation",
    ds.Tables["authors"].Columns["au_id"],
    ds.Tables["titles"].Columns["au_id"]);

解决方案 »

  1.   

    DataRelation objRelation; // create a Relation object to link Books and Authors
    objRelation = new DataRelation("BookAuthors",
    objDataSet.Tables["Books"].Columns["ISBN"],
    objDataSet.Tables["Authors"].Columns["ISBN"]);
    // and add it to the DataSet object's Relations collection
    objDataSet.Relations.Add(objRelation); // now do the same to link Books and Prices
    objRelation = new DataRelation("BookPrices",
    objDataSet.Tables["Books"].Columns["ISBN"],
    objDataSet.Tables["Prices"].Columns["ISBN"]);
    objDataSet.Relations.Add(objRelation); // now we're ready to display the contents of the DataSet object
    // bind the collection of Tables to the first DataGrid on the page
    dgrTables.DataSource = objDataSet.Tables;
    dgrTables.DataBind(); // bind the collection of Relations to the second DataGrid on the page
    dgrRelations.DataSource = objDataSet.Relations;
    dgrRelations.DataBind(); // create a DataView object to use with the tables in the DataSet
    DataView objDataView = new DataView(); // get the default view of the Books table into the DataView object
    objDataView = objDataSet.Tables["Books"].DefaultView;
    // and bind it to the third DataGrid on the page
    dgrBooksData.DataSource = objDataView;
    dgrBooksData.DataBind(); // then do the same for the Authors table
    objDataView = objDataSet.Tables["Authors"].DefaultView;
    dgrAuthorsData.DataSource = objDataView;
    dgrAuthorsData.DataBind(); // and finally do the same for the Prices table
    objDataView = objDataSet.Tables["Prices"].DefaultView;
    dgrPricesData.DataSource = objDataView;
    dgrPricesData.DataBind();