Danh mục

Practical Database Programming With Visual C#.NET- P3

Số trang: 50      Loại file: pdf      Dung lượng: 916.98 KB      Lượt xem: 10      Lượt tải: 0    
Hoai.2512

Hỗ trợ phí lưu trữ khi tải xuống: 19,000 VND Tải xuống file đầy đủ (50 trang) 0
Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu practical database programming with visual c#.net- p3, công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Practical Database Programming With Visual C#.NET- P3 3.4 Components of ADO.NET 2.0 123 In addition to a schema, a DataTable must also have rows to contain and order data.The DataRow class represents the actual data contained in a table. You use the DataRowand its properties and methods to retrieve, evaluate, and manipulate the data in a table.As you access and change the data within a row, the DataRow object maintains both itscurrent and original state.3.4.7.1 DataTable ConstructorThe DataTable has four overloaded constructors and Table 3.18 lists three of the mostoften used constructors. You can create a DataTable object by using the appropriateDataTable constructor. You can add it to the DataSet by using the Add method to addit to the DataTable object’s Tables collection. You can also create DataTable objects within a DataSet by using the Fill() orFillSchema() methods of the DataAdapter object, or from a predefined or inferred XMLschema using the ReadXml(), ReadXmlSchema(), or InferXmlSchema() methods of theDataSet. Note that after you have added a DataTable as a member of the Tables collec-tion of one DataSet, you cannot add it to the collection of tables of any other DataSet. When you first create a DataTable, it does not have a schema (that is, a structure).To define the schema of the table, you must create and add DataColumn objects to theColumns collection of the table. You can also define a primary key column for the tableand create and add Constraint objects to the Constraints collection of the table. Afteryou have defined the schema for a DataTable, you can add rows of data to the table byadding DataRow objects to the Rows collection of the table. You are not required to supply a value for the TableName property when you createa DataTable; you can specify the property at another time, or you can leave it empty.However, when you add a table without a TableName value to a DataSet, the table willbe given an incremental default name of TableN, starting with “Table” for Table0. Figure 3.17 shows an example of creating a new DataTable and a DataSet and thenadding the DataTable into the DataSet object.Table 3.18 Three Popular Constructors of the DataTable ClassConstructors DescriptionsDataTable() Initializes a new instance of the DataTable class with no arguments.DataTable(String) Initializes a new instance of the DataTable class with the specified table name.DataTable(String, String) Initializes a new instance of the DataTable class using the specified table name and namespace. DataSet FacultyDataSet; DataTable FacultyTable; FacultyDataSet = new DataSet(); FacultyTable = new DataTable(“Faculty”); FacultyDataSet.Tables.Add(FacultyTable);Figure 3.17 Example of adding a DataTable into a DataSet.124 Chapter 3 Introduction to ADO.NETTable 3.19 Popular Properties of the DataTable ClassProperties DescriptionsColumns The data type of the Columns property is DataColumnCollection, which means that it contains a collection of DataColumn objects. Each column in the DataTable can be considered as a DataColumn object. By calling this property, a collection of DataColumn objects that exists in the DataTable can be retrieved.DataSet Gets the DataSet to which this table belongs.IsInitialized Gets a value that indicates whether the DataTable is initialized.Namespace Gets or sets the namespace for the XML representation of the data stored in the DataTable.PrimaryKey Gets or sets an array of columns that function as primary keys for the data table.Rows The data type of the Rows property is DataRowCollection, which means that it contains a collection of DataRow objects. Each row in the DataTable can be considered as a DataRow object. By calling this property, a collection of DataRow objects that exists in the DataTable can be retrieved.TableName Gets or sets the name of the DataTable. First, you need to create an instance for both the DataSet and the DataTable classes,respectively. Then you can add this new DataTable instance into the new DataSet objectby using the Add() method.3.4.7.2 DataTab ...

Tài liệu được xem nhiều: