Mã này bắt đầu với các tờ khai cho mộtConstraintCollection và một đối tượng DataColumn để giữ cột chúng tôi muốn thiết lập các hạn chế (trong trường hợp này cột CustomerID). Chúng tôi sử dụng phương thức Add của ConstraintCollection, đi qua trong tên của một ràng buộc, đối tượng DataColumn, | Data Access with We can also add a UniqueConstraint to the Constraintcollection to ensure that the primary key of a column is unique. This is a very similar process to setting the primary key shown earlier. Declare a Constraintcollection. Dim myCKey As Constraintcollection Dim myColumn As DataColumn Get the column we want to place a unique constraint on. myColumn Customers .Columns CustomerID Add the constraint to the constraint collection. MyConstraint myColumn True Add the constraint collection to the table s constraint collection. Customers . mCKey This code starts with declarations for a ConstraintCollection and a DataColumn object to hold the column we want to set the constraint for in this case the CustomerID column . We use the Add method of the ConstraintCollection passing in the name of a constraint the DataColumn object and a Boolean parameter indicating if this is a primary key. We then call the Add method of the Tables. Constraints property and pass in the ConstraintCollection object. There are many objects that work together to make up the DataSet object. They all work hand and hand to build the tables schema as well as manage the data. Next we will see how to save changes that are made to a DataSet on the server. Updating the Database Once changes are made to a DataSet how do we update those changes back to the database Earlier we showed how calling the AcceptChanges method updates only local records and not the database proper. These methods we use next assume you haven t called AcceptChanges on any of your modified records before you post changes to the server. We have a couple of methods for updating our database. To update a DataSet call the Update method of the DataAdapter. This can take a DataSet DataTables or an array of DataRow objects and examines the RowState property to determine which rows have changed. Then Insert Update or Delete is executed depending on the state of the