强类型数据集

上传人:碎****木 文档编号:220862848 上传时间:2021-12-09 格式:DOCX 页数:7 大小:22.75KB
返回 下载 相关 举报
强类型数据集_第1页
第1页 / 共7页
强类型数据集_第2页
第2页 / 共7页
强类型数据集_第3页
第3页 / 共7页
亲,该文档总共7页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《强类型数据集》由会员分享,可在线阅读,更多相关《强类型数据集(7页珍藏版)》请在金锄头文库上搜索。

1、一强类型数据集:强类型数据集实现为一系列的类,这些类派生自组成数据集的那些基类。派生于 DataSet 的强类型数据集,派生于DataTable 的强类型数据表,派生于DataRow 的强类型数据行。这些派生类都定义了多个附加的属性和方法,为根底类数据供给了类型平安的访问。TypedDataSet.TypedDataTablen. TypedProperty1) TypedDataSet:强类型数据集,返回强类型的数据集。2) TypedDataSet.TypedDataTable:强类型数据表,返回强类型的数据表3 TypedDataTablen:强类型索引,返回强类型数据行4 TypedP

2、roperty:强类型列属性。列的强类型访问,返回列类型的实例。DataSet. Tablesn. Rowsm DataColumn| int |string columnName1 DataSet:DataSet 返回。2 Tablesn:返回 DataTable。3 Rowsm:返回DataRow。4 Rowsm DataColumn| int |string columnName:返回Object 类型的引用。强类型类使用了Partial 类特性,Partial 类允许一个类定义存在于一个工程的多个文件中。使用类允许在工程中的某个单独的文件中为强类型数据集补充代码去实现验证规律或商业规律

3、。假设重新生成强类型数据集,这个单独文件的代码不会受到影响。1. 强类型数据集中1) 强类型数据表属性供给了对强类型数据集中强类型数据表实例的类型平安的访问。供给了类型平安,并且可以提高设计效率和运行效率主要相对于字符串而言。(1) DataSet 中,Tables 索引器通过集合访问public DataTable this string name| int index get; DataTable employees = dataset.Tables“Employees”|0;(2) 强类型数据集中, 强类型数据表属性 通过私有数据成员tableEmployees 来访问表对象public

4、 EmployeesDataTable Employeesget return this.tableEmployees;EmployeesDataTable employees = dataset. Employees;2. 强类型数据表中1) DataColumn 的命名属性对于数据表中的每个列,都有一个对应类型为 DataColumn 的命名属性, 这些属性可以通过名称来获得这些数据列的类型信息访问。可以提高设计效率和运行效率主要相对于字符串而言。1 DataTable 中, Columns 索引器通过集合访问public DataColumn this string name| int

5、index get; DataColumn employeeIDColumn = dataset.Tables“EmployeeID”|0;7(2)强类型数据表中,DataColumn 的命名属性通过私有数据成员访问public global:System.Data.DataColumn EmployeeIDColumnget return this.columnEmployeeID; DataColumn employeeIDColumn = dataset. EmployeeIDColumn;2) 迭代访问及强类型索引器均访问数据行集合强类型数据表供给了一个强类型数据行索引器,通过它可以用

6、类型平安的强类型数据表类的实例访问表中的全部强类型数据行。供给了类型平安。实现了迭代接口IEnumerable,可以迭代访问表中的全部强类型数据行。(1) DataTable 中, 未实现迭代接口 IEnumerable,无 DataRow 索引器和Count 属性,不能直接迭代访问表中的数据行,只能通过数据行集合迭代访问表中的数据行。public DataRow this int index get; public override int Count get; (2) 强类型数据表中,实现了迭代接口IEnumerable,实现了实例迭代访问。类型平安的索引器、Count 属性与迭代访问无关

7、。强类型数据表中,类型平安的索引器,返回强类型数据行。public EmployeesRow thisint indexget return (EmployeesRow)(this.Rowsindex); 强类型数据表中,Count属性,返回数据行的数量。public int Countget return this.Rows.Count; 强类型数据表中,IEnumerable.GetEnumerator接口方法,返回IEnumerator接口变量。强类型数据表中的迭代访问与通过数据行集合迭代访问表中的数据行本质上是一样的。public virtual IEnumerator GetEnum

8、erator()return this.Rows.GetEnumerator();foreach (NorthwindDataSet.CustomersRow rowCustomer indsNorthwind.Customers) foreach (NorthwindDataSet.CustomersRow rowCustomer indsNorthwind.Rows) 3) 类型平安的方法(1) NewEmployeesRow,创立一个强类型的新的数据行public EmployeesRow NewEmployeesRow()return (EmployeesRow)(this.NewRo

9、w();(2) AddEmployeesRow,在数据行集合中插入一个强类型的新的数据行public void AddEmployeesRow(EmployeesRow row)this.Rows.Add(row);4) 强类型大事public event EmployeesRowChangeEventHandler EmployeesRowChanging; public event EmployeesRowChangeEventHandler EmployeesRowChanged; public event EmployeesRowChangeEventHandler Employees

10、RowDeleting; public event EmployeesRowChangeEventHandler EmployeesRowDeleted;public delegate void EmployeesRowChangeEventHandler(object sender,EmployeesRowChangeEvent e);public class EmployeesRowChangeEvent : global:System.EventArgsprivate EmployeesRow eventRow;private global:System.Data.DataRowActi

11、on eventAction; public EmployeesRowChangeEvent(EmployeesRow row,System.Data.DataRowAction action)this.eventRow = row; this.eventAction = action;public EmployeesRow Rowget return this.eventRow; public global:System.Data.DataRowAction Actionget return this.eventAction;3. 强类型数据行中1) 通过强类型的属性显示行中的每一列的值(1

12、) 通过DataRow 索引器显示行中的每一列的值通过集合访问public Object this DataColumn| int |string columnName get; set; (2) 通过强类型的列属性显示行中的每一列的值没有任何硬编码的架构引用,没有表名或列明的任何字符串文本, 而且也不需要按列的位置来索引访问列。都是通过强类型行对象显示的强类型列属性来访问的。public string FirstName get return (string)(thisthis.tableEmployees.FirstNameColumn);set thisthis.tableEmploye

13、es.FirstNameColumn = value;global:System.Diagnostics.DebuggerNonUserCodeAttribute() public bool IsBirthDateNull() return this.IsNull(this.tableEmployees.BirthDateColumn);global:System.Diagnostics.DebuggerNonUserCodeAttribute() public void SetBirthDateNull() thisthis.tableEmployees.BirthDateColumn =

14、global:System.Convert.DBNull;public EmployeesRow GetEmployeesRows() if (this.Table.ChildRelations“FK_Employees_Employees“ = null) return new EmployeesRow0;else return(EmployeesRow)(base.GetChildRows(this.Table.ChildRelations “FK_Employees_Employees“);(3) 通过方法校验数据列是否为空。public bool IsCustomerIDNull() return this.IsNull(this.tableOrders.CustomerIDColumn);2) 关系导航public EmployeesRow EmployeesRowParent get returnset (EmployeesRow)(this.GetParentRow(this.Table.ParentRelations“FK_ Employees_Employees“);this.SetParentRow(value,this.Table.ParentRelations“F

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 教育/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号