国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

Working with Relational Data in ADO.Net(東方蜘蛛快來(lái)看?。。?/h1>
2024-07-10 13:03:27
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

working with relational data in ado.netsubmitted byuser leveldate of submissionc.vinodh kumarintermediate04/03/2001
working with hierarchal data was not that easy with the previous version of ado. with the advent of ado.net things are made much easier for the programmers. they need not write complex data shape query to get the hierarchal output (hierarchal recordset抯 in ado).
ado.net dataset

the dataset object is central to ado.net. the dataset is a simple memory-resident database which provides a consistent programming model regardless of the data source. the dataset represents a complete set of data including related tables, constraints, and relationships among the tables. in ado.net, dataset is a collection of one or more tables represented by datatable objects. the table collection object contains all the datatable objects in a dataset.
a typical dataset contains relationships contained by the relationscollection object. a relationship, represented by the datarelation object, associates rows in one table to the rows in another table. it is similar to the foreign-key relationship in a relational database. a datarelation identifies matching columns in two tables of a dataset.
a dataset can contain either related or unrelated data. a dataset can either have two unrelated or 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 hierarchical paradigm. because data is often stored in relational databases, the dataset can handle both hierarchical relationships and foreign key relationships. relationships can also have different types of enforcement. by default, deletions and updates are cascaded. a dataset contains a relations collection. it is easy to add a relationship to this collection using the column or columns (in a multi-column key) of the related tables.
the example below presumes two datatable objects exist in the dataset. both tables have a column named "custid" which serves as the link between the two tables. the example adds a single datarelation to the relations collection of the dataset object. the first argument ("custorders") specifies the name of the relationship. the second and third arguments are the datacolumn objects that link the two tables.
  
//constructs an instance of a dataset<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
    dataset ds = new dataset("customerorders");
                 // add a datarelation to the relations collection specifying its name,
                 // and the appropriate datacolumn objects as arguments.
 ds.relations.add("custorders",ds.tables["customers"].columns["custid"],
     ds.tables["orders"].columns["custid"]);
//  you can also set the relation like the one given below
datarelation dr;
dr = new datarelation("custorders",ds.tables["customers"].columns["custid"],
                        ds.tables["orders"].columns["custid"]);
ds.relations.add(dr)

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.
retrieving data from the relationship.
  
foreach (datarow customer in dscustomers.tables["customers"].rows) {
    response.write("customer: " + customer["contactname"].tostring());
    foreach (datarow order in customer.getchildrows(dscustomers.relations["custorders"])) {
        response.write("order #" + order["orderid"].tostring());
    }
}

a primary function of the datarelation is to allow navigation from one table to another within the dataset. in practice, this allows us to retrieve all  the related datarow objects in one table when given a single datarow from a related table. the above example gives a datarow from the customers table; we can retrieve all  the orders for a particular customer from the orders table.
getchildrow method gets the specified child rows of this datarow using the named datarelation.
the relational output from the customer and orders table will be the same as below (one-to-many relation).

customer: maria anders
order #10643
order #10692
order #10702
order #10835
order #10952
order #11011
customer: ana trujillo
order #10308
order #10625
order #10759
order #10926
厖厖?
厖厖?

conclusion
in this article, we have started with an introduction to the types of relationships and have learnt how to get the relational data using ado+ dataset and datarelation.in particular ado.net offers several advantages over previous versions of ado and over other data access components. these benefits fall into the following categories: interoperability, maintainability, programmability, and performance.
source code:  datarelation.zip
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

主站蜘蛛池模板: 阳原县| 米脂县| 嫩江县| 汾阳市| 四子王旗| 阜宁县| 百色市| 和龙市| 长阳| 新乡市| 延边| 华亭县| 西畴县| 马龙县| 道孚县| 郸城县| 张家港市| 翼城县| 平昌县| 石楼县| 罗源县| 阿合奇县| 南充市| 盈江县| 青海省| 龙江县| 诸城市| 阳东县| 米林县| 措勤县| 洛浦县| 长武县| 德格县| 长海县| 玉屏| 夏邑县| 永福县| 汉阴县| 西青区| 绥芬河市| 万载县|