và InsertCommand thuộc tính với các đối tượng lệnh có giá trị (cho đến khi bạn làm như vậy, những tài sản này trả lại tài liệu tham khảo vô giá trị). Bởi các đối tượng lệnh "hợp lệ", tôi đề cập đến các thiết lập của các đối tượng lệnh được sử dụng kết hợp với bảng bạn đang cố gắng để cập nhật (bảng tồn kho trong ví dụ của chúng tôi). | Simpo PDF Merge and Split Unregistered Version - http 812 CHAPTER 23 PART II THE DISCONNECTED LAYER Configuring the Data Adapter Using the SqlCommandBuilder When you are using a data adapter to modify tables in a DataSet the first order of business is to assign the UpdateCommand DeleteCommand and InsertCommand properties with valid command objects until you do so these properties return null references . By valid command objects I am referring to the set of command objects used in conjunction with the table you are attempting to update the Inventory table in our example . To fill up our adapter with the necessary data can entail a good amount of code especially if we make use of parameterized queries. Recall from Chapter 22 that a parameterized query allows us to build a SQL statement using a set of parameter objects. Thus if we were to take the long road we could implement ConfigureAdapter to manually create three new SqlCommand objects each of which contains a set of SqlParameter objects. After this point we could set each object to the UpdateCommand DeleteCommand and InsertCommand properties of the adapter. Thankfully Visual Studio 2008 provides a number of designer tools to take care of this mundane and tedious code on our behalf. You ll see some of these shortcuts in action at the conclusion of this chapter. Rather than forcing you to author the numerous code statements to fully configure a data adapter let s take a massive shortcut by implementing ConfigureAdapter as so private void ConfigureAdapter out SqlDataAdapter dAdapt Create the adapter and set up the SelectCommand. dAdapt new SqlDataAdapter Select From Inventory cnString Obtain the remaining command objects dynamically at runtime using the SqlCommandBuilder. SqlCommandBuilder builder new SqlCommandBuilder dAdapt To help simplify the construction of data adapter objects each of the Microsoft-supplied data providers provides a command builder type. The SqlCommandBuilder