Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Adding Restrictions to DataTable and DataColumn Objects As you know, a DataSet object is used to store a copy of a subset of the database. For example, you can store a copy of the rows from database tables into a DataSet | Adding Restrictions to DataTable and DataColumn Objects As you know a DataSet object is used to store a copy of a subset of the database. For example you can store a copy of the rows from database tables into a DataSet with each table represented by a DataTable object. A DataTable stores columns in DataColumn objects. In addition to storing rows retrieved from a database table you can also add restrictions to a DataTable and its DataColumn objects. This allows you to model the same restrictions placed on the database tables and columns in your DataTable and DataColumn objects. For example you can add the following constraints to a DataTable Unique Primary key Foreign key In addition you can add the following restrictions to a DataColumn Whether the column can accept a null value-which you store in the AllowDBNull property of the DataColumn. Any auto-increment information-which you store in the AutoIncrement AutoIncrementSeed and AutoIncrementStep properties of the DataColumn. You set these properties when adding rows to a DataTable with a corresponding database table that contains an identity column. The ProductID column of the Products table is an example of an identity column. Note ADO.NET will not automatically generate values for identity columns in a new row. Only the database can do that. You must read the generated identity value for the column from the database. You ll see how to do that later in the sections Retrieving New Identity Column Values and Using Stored Procedures to Add Modify and Remove Rows from the Database. Also if your database table contains columns that are assigned a default value you should read that value from the database. This is better than setting the DefaultValue property of a DataColumn because if the default value set in the database table definition changes you can pick up the new value from the database rather than having to change your code. The maximum length of a string or character column value-which you store in the .