home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / howto / doc / adoplus / relationaldata.aspx < prev    next >
Encoding:
Text File  |  2000-06-09  |  2.4 KB  |  40 lines

  1.  
  2. <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
  3.  
  4. <!-- #include virtual="/quickstart/include/header.inc" -->
  5.  
  6. <h4>ADO+: Relational Data</h4>
  7. <p>
  8. <hr>
  9. <p>
  10. A DataSet can contain either related or unrelated data. A DataSet can either have two unrelated tables, or two related tables. A DataSet can be thought of as a document of Data. In fact, an XML data document is like this, except it is based on a hierachical paradigm. Because data is often stored in relational databases, the DataSet can handle both hierachical relationships and key/foreign key relationships. Relationships can also have different types of enforcement. By default, deletions and updates are cascaded: if you delete a Customer Row, the related Orders rows are also deleted; if you Update the key of a Customer Row, the associated foreign key values in the Orders table is also updated.
  11. <p>
  12. A DataSet contains a Relations collection. It is easy to add a relationship to this collection using the column or columns (in a muli-column key) of the related tables. For example, imagine you have a DataSet with Customers and Orders data, and you want to create a relation between the two:
  13. <p>
  14. <div class=code>
  15.     dsCustomers.Relations.Add("CustOrders",myDataSet.Tables["Customers"].Columns["CustomerId"],myDataSet.Tables["Orders"].Columns["CustomerId"]);
  16. </div>
  17. <p>
  18. This code adds a relation between the CustomerId Key on the Customers table and the CustomerId foreign key on the Orders table in the DataSet. Now that a relationship exists, you can iterate through the data, using the relationship, in a meaningful way.
  19. <p>
  20. <div class=code>
  21. <BR>foreach (DataRow Customer in dsCustomers.Tables["Customers"].Rows)
  22. <BR>    {
  23. <BR><blockquote>Response.Write("<br>Customer: " + Customer["ContactName"].ToString());
  24. <BR>        foreach (DataRow Order in Customer.GetChildRows(dsCustomers.Relations["CustOrders"]))
  25. <BR>        {
  26. <BR><blockquote>    Response.Write("<br>Order #" + Order["OrderId"].ToString());</blockquote>
  27. <BR>        }</blockquote>
  28. <BR>    }
  29. </DIV>
  30. <p>
  31. The sample below iterates over the data as explained above and outputs it to a web page hierarchically.
  32. <p>
  33. <Acme:SourceRef 
  34.   RunSample="/quickstart/howto/samples/adoplus/cs/RelationalData.aspx" 
  35.   ViewSource="/quickstart/howto/samples/adoplus/cs/RelationalData.src"
  36.   Icon="/quickstart/images/genicon.gif"
  37.   Caption="RelationalData.aspx"
  38.   runat="server" />
  39. </a>
  40.